-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path189.py
26 lines (22 loc) · 906 Bytes
/
189.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Solution:
def rotate(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: void Do not return anything, modify nums in-place instead.
"""
if len(nums) <= 1 or (k % len(nums) == 0):
return
for i in range((len(nums) - k % len(nums)) // 2):
temp = nums[i]
nums[i] = nums[len(nums) - k % len(nums) - 1 - i]
nums[len(nums) - k % len(nums) - 1 - i] = temp
for i in range(k % len(nums) // 2):
temp = nums[i + len(nums) - k % len(nums)]
nums[i + len(nums) - k % len(nums)] = nums[len(nums) - 1 - i]
nums[len(nums) - 1 - i] = temp
for i in range(len(nums) // 2):
temp = nums[i]
nums[i] = nums[len(nums) - 1 - i]
nums[len(nums) - 1 - i] = temp
return