Java O(1) space solution of Rotate Array.
The basic idea is that, for example, nums = [1,2,3,4,5,6,7] and k = 3, first we reverse [1,2,3,4], it becomes[4,3,2,1]; then we reverse[5,6,7], it becomes[7,6,5
The basic idea is that, for example, nums = [1,2,3,4,5,6,7] and k = 3, first we reverse [1,2,3,4], it becomes[4,3,2,1]; then we reverse[5,6,7], it becomes[7,6,5], finally we reverse the array as a whole, it becomes[4,3,2,1,7,6,5] ---> [5,6,7,1,2,3,4].\n\nReverse is done by using two pointers, one point at the head and the other point at the tail, after switch these two, these two pointers move one position towards the middle. \n\n\npublic class Solution {\n\n    public void rotate(int[] nums, int k) {\n\n        if(nums == null || nums.length < 2){\n            return;\n        }\n        \n        k = k % nums.length;\n        reverse(nums, 0, nums.length - k - 1);\n        reverse(nums, nums.length - k, nums.length - 1);\n        reverse(nums, 0, nums.length - 1);\n        \n    }\n    \n    private void reverse(int[] nums, int i, int j){\n        int tmp = 0;       \n        while(i < j){\n            tmp = nums[i];\n            nums[i] = nums[j];\n            nums[j] = tmp;\n            i++;\n            j--;\n        }\n    }\n}
[]