[Python] 2 solutions - Clean & Concise
\u2714\uFE0F Solution 1: Using Extra Space\npython\nclass Solution:\n    def rotate(self, nums: List[int], k: int) -> None:\n        n = len(nums)\n        k %=
**\u2714\uFE0F Solution 1: Using Extra Space**\n```python\nclass Solution:\n    def rotate(self, nums: List[int], k: int) -> None:\n        n = len(nums)\n        k %= n\n        ans = [0] * n\n        \n        for i in range(n):\n            ans[(i+k)%n] = nums[i]\n            \n        for i in range(n):\n            nums[i] = ans[i]\n```\nComplexity:\n- Time: `O(N)`, where `N` is length of `nums` array.\n- Space: `O(N)`\n\n---\n**\u2714\uFE0F Solution 2: Reverse array**\n- Example Input: [1, 2, 3, 4, 5, 6], k = 2\n- Expect Output: [5, 6, 1, 2, 3, 4]\n- The idea is that we do 3 reverse\n- Reverse the whole array, it becomes: [6, 5, 4, 3, 2, 1]\n- Reverse first `k` elements, it becomes: [5, 6, 4, 3, 2, 1]\n- Reverse the last `n-k` elements, it becomes: [5, 6, 1, 2, 3, 4]\n```python\nclass Solution:\n    def rotate(self, nums: List[int], k: int) -> None:\n        def reverse(arr, left, right):\n            while left < right:\n                arr[left], arr[right] = arr[right], arr[left]\n                left += 1\n                right -= 1\n                \n        n = len(nums)\n        k %= n\n        reverse(nums, 0, n - 1)\n        reverse(nums, 0, k-1)\n        reverse(nums, k, n-1)\n```\nComplexity:\n- Time: `O(N)`, where `N` is length of `nums` array.\n- Space: `O(1)`
[]