Why? k=k%nums.size();


  • 0
    T

    class Solution {
    public:

    void rotate(vector<int>& nums, int k) 
    {
        vector<int>result(nums.size(),0);
        k=k%nums.size();
        int aa=nums.size()-k;
        
        for(int i=aa;i<nums.size();i++)
        {
            result[i-aa]=nums[i];
        }
        for(int j=0;j<aa;j++)
        {
            result[k]=nums[j];
            k++;
        }
        nums=result;
    }
    

    };


  • 0
    C

    the rotation repeats itself every array size.Solving for any x*array size +n =solving for n


Log in to reply
 

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