Concise and easy understand java solution


  • 0
    B
     public void rotate(int[] nums, int k) {
        int[] res = nums.clone();
        k = k%res.length;
        int index = 0;
        for(int i = res.length-k; i< res.length;i++){
        	nums[index] = res[i];
        	index++;
        }
        for(int i = 0;i<res.length-k;i++){
        	nums[index] = res[i];
        	index++;
        }
    }

Log in to reply
 

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