class Solution
{
public:
    //数组反转函数
    void reverseArray(vector<int> &array, int begin, int end)
    {
        int temp, tmp_end = end;
        for (int i = begin; i <= (begin + end) / 2; i++)
        {
            temp = array[i];
            array[i] = array[tmp_end];
            array[tmp_end] = temp;
            tmp_end--;
        }
    }

    void rotate(vector<int> &nums, int k)
    {
        int len = nums.size();
        k %= len;
        if (k == 0)
            return;
        //使用自定义的反转函数
        reverseArray(nums, 0, len - k - 1);
        reverseArray(nums, len - k, len - 1);
        reverseArray(nums, 0, len - 1);

        //使用C++自带的反转函数
        /*reverse(nums.begin(), nums.end() - k);
	    reverse(nums.end() - k, nums.end());
	    reverse(nums.begin(), nums.end());*/
    }
};