My accepted simple solution in java


  • 1
    J
    public class Solution {
    public void rotate(int[] nums, int k) {
        int n=nums.length;
        int [] ret=new int [n];
        for(int i=0;i<n;i++)
        {
            ret[(i+k)%n]=nums[i];
        }
        for(int i=0;i<n;i++)
        {
            nums[i]=ret[i];
        }
    }
    

    }


Log in to reply
 

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