Using only system function in java


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

Log in to reply
 

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