Simple 24ms c++ solution with STL


  • 4
    L
    void rotate(vector<int>& nums, int k) {
        k%=nums.size();
        vector<int> roll(nums.end()-k,nums.end());
        nums.erase(nums.end()-k,nums.end());
        nums.insert(nums.begin(),roll.begin(),roll.end());
    }

  • 0
    1

    woa!! your code is very easy to understand , thanks so much


Log in to reply
 

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