My java Solution


  • 0
    C
    public class Solution {
    public void rotate(int[] nums, int k) {
    if(nums.length<=1)return;
    if(nums.length == k)return;
    if(k>nums.length)
    {
        k = k%nums.length;
    }
    
    int[] remain = new int[k];
    int j=0;
    for(int i=nums.length-k;i<nums.length;i++)
    {
    	remain[j++] = nums[i];
    }
    
    for(int i=nums.length-k-1;i>=0;i--)
    {
    	nums[i+k] = nums[i];
    }
    
    for(int i=0;i<k;i++)
    {
    	nums[i] = remain[i];
    }
    }
    

    }


Log in to reply
 

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