C++ solution,4lines


  • 0
    W
    class Solution {
    public:
        void rotate(vector<int>& nums, int k) {
            int numslen=nums.size(),ktmp=k%numslen;
            vector<int> tmp1(nums.begin(),nums.begin()+numslen-ktmp);
            tmp1.insert(tmp1.begin(),nums.begin()+numslen-ktmp,nums.end());
            nums=tmp1;
        }  
    };
    

Log in to reply
 

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