A C# Copy Array Solution O(K) space


  • 1
    L
    public void Rotate(int[] nums, int k) {
        k %= nums.Count();
        int[] tmp = new int[k];
        Array.Copy(nums, nums.Count() - k, tmp, 0, k);
        Array.Copy(nums, 0, nums, k, nums.Count() - k);
        Array.Copy(tmp, 0, nums, 0, k);
    }

Log in to reply
 

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