Simple solution but not ideal


  • 0
    V

    public class Solution {

    public void rotate(int[] nums, int k) {
        int n = nums.length;
        while(k>n) {
            k -= n;
        }
        int[] temp = new int[k];
        System.arraycopy(nums, n-k, temp, 0, k);
        System.arraycopy(nums, 0, nums, k, n-k);
        System.arraycopy(temp, 0, nums, 0, k);
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.