5 line simple c++ solution using just push_back


  • 0
    X
    void rotate(vector<int>& nums, int k)  
    {   
            int n=nums.size();
            vector<int> head;
            for(int i=0;i<nums.size();i++)
                head.push_back(nums[((i-k+k*n)%n)]);
            nums=head;
    }

Log in to reply
 

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