Easier Java Solution


  • 1
    S

    public class Solution {
    public void rotate(int[] nums, int k) {
    int length = nums.length;
    int[] nums2 = new int[2 * length];
    for(int i = 0; i < length; i++) {
    nums2[i] = nums[i];
    nums2[length + i] = nums[i];
    }
    for(int i = 0; i < length; i++) {
    nums[i] = nums2[length - k % length + i];
    }
    }
    }


Log in to reply
 

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