Java 0ms elegant solution ,easy to understand


  • 1
    public void rotate(int[] nums, int k) {
            
            int len = nums.length;
            int pos = len - k%len;
            
            int[] arr = new int[len*2];
            System.arraycopy(nums,0 ,arr,0,len);
            System.arraycopy(nums,0 ,arr,len,len);
            
            System.arraycopy(arr,pos ,nums,0,len);
            
        }
    

Log in to reply
 

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