0ms Simple Java Solution

  • 0
    public class Solution {
        public void rotate(int[] nums, int k) {
            if(k > nums.length) k %= nums.length;
            int[] first = new int[k];
            System.arraycopy(nums, nums.length-k, first, 0, k);
            System.arraycopy(nums, 0, nums, k,nums.length-k);
            System.arraycopy(first,0, nums, 0, k );

Log in to reply

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