Skip to content

Commit e287c53

Browse files
Create 0189-rotate-array.py
This is a transcription of the python code which is provided in the video https://www.youtube.com/watch?v=BHr381Guz3Y.
1 parent e4338a9 commit e287c53

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

python/0189-rotate-array.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution:
2+
def rotate(self, nums: List[int], k: int) -> None:
3+
"""
4+
Do not return anything, modify nums in-place instead.
5+
"""
6+
k = k % len(nums)
7+
l, r = 0, len(nums) - 1
8+
while l < r:
9+
nums[l], nums[r] = nums[r], nums[l]
10+
l, r = l + 1, r - 1
11+
12+
l, r = 0, k - 1
13+
while l < r:
14+
nums[l], nums[r] = nums[r], nums[l]
15+
l, r = l + 1, r - 1
16+
17+
l, r = k, len(nums) - 1
18+
while l < r:
19+
nums[l], nums[r] = nums[r], nums[l]
20+
l, r = l + 1, r - 1

0 commit comments

Comments
 (0)