s4553711
8/26/2017 - 3:10 PM

189.cpp

class Solution {
public:
    void rotate(vector<int>& nums, int k) {
        int n = nums.size();
        k=k%n;
        reverse(nums,0,n-k-1);
        reverse(nums,n-k,n-1);
        reverse(nums,0,n-1);
    }
private:
    void reverse(vector<int>& nums,int low, int high) {
        while(low <= high){
            swap(nums[low], nums[high]);
            low++;
            high--;
        }
    }    
};