Skip to content

Commit

Permalink
189
Browse files Browse the repository at this point in the history
  • Loading branch information
luanshiyinyang committed Oct 13, 2021
1 parent f0e4ff5 commit a9401f7
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions 0189-Rotate Array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Solution:
def rotate(self, nums: List[int], k: int) -> None:
"""
Do not return anything, modify nums in-place instead.
"""
n = len(nums)
count = 0
start = 0
while count < n:

current = start
pre = nums[current]

while True:
next_index = (current + k) % n
temp = nums[next_index]
nums[next_index] = pre
current = next_index
pre = temp
count += 1
if start == current:
break

start += 1

0 comments on commit a9401f7

Please sign in to comment.