EASY c++ solution pop_back and insert it back


  • 0
    H
    class Solution {
    public:
        void rotate(vector<int>& nums, int k) {
            int n = nums.size();
            if(nums.empty()||k<0)return;
            k%=n;
            for(int i = 0;i<k;++i){
                nums.insert(nums.begin(),nums.back());
                nums.pop_back();
            }
            return;
        }
    };

Log in to reply
 

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