3-lines of c++ using insert and resize


  • 0
    N

    Here is my code.

    class Solution {
    public:
        void rotate(vector<int>& nums, int k) {
            for(int i=0;i<k;i++){
                nums.insert(nums.begin(),nums[nums.size()-1]);
                nums.resize(nums.size());
            }
        }
    };
    

Log in to reply
 

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