Skip to content

Commit ee427a5

Browse files
Time: 323 ms (54.52%), Space: 25.3 MB (85.28%) - LeetHub
1 parent 9d88925 commit ee427a5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution:
2+
def rotate(self, nums: List[int], k: int) -> None:
3+
n = len(nums)
4+
k %= n
5+
6+
print(k)
7+
8+
start = count = 0
9+
while count < n:
10+
current, prev = start, nums[start]
11+
while True:
12+
next_idx = (current + k) % n
13+
nums[next_idx], prev = prev, nums[next_idx]
14+
current = next_idx
15+
count += 1
16+
17+
if start == current:
18+
break
19+
start += 1

0 commit comments

Comments
 (0)