Easy to understand C# solution


  • 0
    K
    public void Rotate(int[] nums, int k) {
    
        if(nums == null || nums.Length < 2 || k == 0)
            return;
        
        int [] arr = new int[nums.Length];
        int n = nums.Length;
        for(int i = 0;i < nums.Length;i++){
            arr[(i + k) % n] = nums[i];
        }
        
        arr.CopyTo(nums , 0);
       
    }

Log in to reply
 

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