It works when i run it in my system


  • 0
    K

    public class Solution {

    public void rotate(int[] nums, int k) {
            int[] dup = null;
    	    k = k%nums.length;
            if(k!=0){
            dup=new int[nums.length];
            System.arraycopy(nums, 0, dup, k, nums.length-k);
            System.arraycopy(nums, nums.length-k,dup,0,k);
            nums=dup;
            }
        
    }
    

    }


  • 0
    K

    public class Solution {

    public void rotate(int[] nums, int k) {
    	int[] dup = null;
    	k = k%nums.length;
    	if(k!=0){
    		dup=new int[nums.length];
    		System.arraycopy(nums, 0, dup, k, nums.length-k);
    		System.arraycopy(nums, nums.length-k,dup,0,k);
    
    		for (int j=0; j<nums.length;j++){
    			nums[j]=dup[j];
    		}
    	}
    
    }
    

    }


Log in to reply
 

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