Summary of solutions in Python
Classical 3-step array rotation:\n> \n> 1. reverse the first n - k elements\n> \n> 2. reverse the rest of them\n> \n> 3. reverse the entire array\n\n    class S
## **Classical 3-step array rotation:**\n> \n> 1. reverse the first n - k elements\n> \n> 2. reverse the rest of them\n> \n> 3. reverse the entire array\n\n    class Solution(object):\n        def rotate(self, nums, k):\n            if k is None or k <= 0:\n                return\n            k, end = k % len(nums), len(nums) - 1\n            self.reverse(nums, 0, end - k)\n            self.reverse(nums, end - k + 1, end)\n            self.reverse(nums, 0, end)\n            \n        def reverse(self, nums, start, end):\n            while start < end:\n                nums[start], nums[end] = nums[end], nums[start]\n                start, end = start + 1, end - 1\n\n**O(n) in time, O(1) in space**\n\n\n## **Rotate `k` times**:\n\nEach rotation, we move the `n - 1` to the back of the array one by one and we do rotation `k` times.\n\n    class Solution(object):\n        def rotate(self, nums, k):\n            k = k % len(nums)\n            for i in xrange(0, k):\n                tmp = nums[-1]\n                for j in xrange(0, len(nums) - 1):\n                    nums[len(nums) - 1 - j] = nums[len(nums) - 2 - j]\n                nums[0] = tmp\n\n**O(n^2) in  time, O(1) in space**\n\n**It can't pass the OJ due to TLE.**\n\n## **Recursive solution** \n\nput the shorter part in the correct position then do the rest of them iteratively. This is not necessarily to be a recursive solution. \n\n    class Solution(object):\n        def rotate(self, nums, k):\n            self.helper(0, len(nums) - 1 - (k % len(nums)), len(nums) - 1, nums) # mid belongs to left part\n    \n        def helper(self, start, mid, end, nums):\n            left, right = mid - start, end - mid - 1\n            if left < 0 or right < 0:\n                return\n            if left > right:\n                for j in xrange(mid + 1, end + 1):\n                    nums[j], nums[start] = nums[start], nums[j]\n                    start += 1\n                self.helper(start, mid, end, nums)\n            elif right >= left:\n                i = mid\n                while i >= start:\n                    nums[i], nums[end] = nums[end], nums[i]\n                    i, end = i - 1, end - 1\n                if left != right:\n                    self.helper(start, mid, end, nums)\n\n**O(n) in time, O(n) in space**\n\n## **Iterative and improved solution:** \n\nput the last `k` elements in correct position (ahead) and do the remaining `n - k`. Once finish swap, the `n` and k decrease.\n\n    class Solution(object):\n        def rotate(self, nums, k):\n            """\n            :type nums: List[int]\n            :type k: int\n            :rtype: void Do not return anything, modify nums in-place instead.\n            """\n            n, k, j = len(nums), k % len(nums), 0\n            while n > 0 and k % n != 0:\n                for i in xrange(0, k):\n                    nums[j + i], nums[len(nums) - k + i] = nums[len(nums) - k + i], nums[j + i] # swap\n                n, j = n - k, j + k\n                k = k % n\n\n**O(n) in time, O(1) in space**
[]