Simple C++ Solution


  • 0
    B
    void rotate(vector<int>& nums, int k) {
            int n = nums.size();
            k = k % n;
            reverse(nums.begin(),nums.begin() + n - k);
            reverse(nums.begin() + n - k,nums.end());
            reverse(nums.begin(),nums.end());
        }

  • 0
    A
    This post is deleted!

Log in to reply
 

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