C# Solution without reverse


  • 0
    N
    public class Solution {
        public void Rotate(int[] nums, int k) {
            var m = new int[nums.Length];
            Array.Copy(nums,m, nums.Length);
            k = k% nums.Length;
            if (k==0) return;
            var temp = nums[k];
            for(var i=0;i<nums.Length;i++){
                nums[(i+k)%nums.Length] = m[i];
            }
        }
    }
    

Log in to reply
 

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