C++ concise solution.


  • 0
    class Solution {
    public:
      void rotate(vector<int>& nums, int k) {
        int n = nums.size();
        k %= n;
        while (k --)
        {
          int tmp = nums[n - 1];
          nums.erase(nums.end() - 1);
          nums.insert(nums.begin(), tmp);
        }
      }
    };
    

Log in to reply
 

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