My c++ ,simple ~~~


  • 0
    K
        class Solution {
    public:
        void rotate(vector<int>& nums, int k) {
            int len=nums.size();
            if(len==1) return;
            k=k%len;
            k=len-k;
            int tem;
            for(int i=0;i<k;i++){
                tem=nums[0];
                nums.erase(nums.begin());
                nums.push_back(tem);
            }
        }
    };

Log in to reply
 

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