My c++ solution, o(n)time && o(1)space
class Solution {\n    public:\n        void rotate(int nums[], int n, int k) {\n            int nowIndex = 0, nextIndex;\n    \t\tint tmp1, tmp2 = nums[0];\n   
    class Solution {\n    public:\n        void rotate(int nums[], int n, int k) {\n            int nowIndex = 0, nextIndex;\n    \t\tint tmp1, tmp2 = nums[0];\n    \t\tfor(int j=0,i=0; j<n; j++){\n    \t\t\ttmp1 = tmp2;\n    \t\t\tnowIndex = (k + nowIndex) % (n);\n    \t\t\ttmp2 = nums[nowIndex];\n    \t\t\tnums[nowIndex] = tmp1;\n    \t\t\tif(nowIndex == i) {\n    \t\t\t\tnowIndex = ++i;\n    \t\t\t\ttmp2 = nums[nowIndex];\n    \t\t\t}\n    \t\t}\n        }\n    };
[]