My solution easy to understand


  • 0
    N

    public static void rotate(int[] nums,int k)

    {
    if(0==k||0==nums.length) return;
    int m=k%(nums.length);
    int[] temp=new int[nums.length];

       temp=nums.clone();
    	for(int i=0;i<nums.length;i++)
    {
    	int temps=(i+m)%(nums.length); 
    	        nums[temps]=temp[i];
    		
    	}
    

    }


Log in to reply
 

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