Easy Java Solution


  • 0
    R
    class Solution {
        public void rotate(int[] nums, int k) {
            if(nums == null || nums.length == 0) return;
            if(k > nums.length) k = k % nums.length;
            int[] a = new int[nums.length];
            System.arraycopy(nums, 0, a, 0, nums.length);
            for(int i = 0; i < nums.length; i++) nums[i] = a[(i + nums.length - k)% nums.length];
        }
    }
    

Log in to reply
 

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