Simple c++ solution with detail explain and O(1) extra space
 /**\n     * this solution is so-called three times rotate method\n     * because (X^TY^T)^T = YX, so we can perform rotate operation three times to get the res
     /**\n     * this solution is so-called three times rotate method\n     * because (X^TY^T)^T = YX, so we can perform rotate operation three times to get the result\n     * obviously, the algorithm consumes O(1) space and O(n) time\n     **/\n    class Solution {\n    public:\n        void rotate(int nums[], int n, int k) {\n            k %= n; // if k > n then the final result is the same as k%n\n            reverseArray(nums, n-k, n-1);\n            reverseArray(nums, 0, n-k-1);\n            reverseArray(nums, 0, n-1);\n            \n        }\n        /**\n         * rotate the array nums from start to end\n        **/\n        void reverseArray(int nums[],int start, int end){\n            while(start < end){\n                int temp = nums[start];\n                nums[start++] = nums[end];\n                nums[end--] = temp;\n                // or you can simply code as "std::swap(nums[start++], nums[end--])" to replace above three lines\n            }\n        }\n    };
[]