We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9d88925 commit ee427a5Copy full SHA for ee427a5
189-rotate-array/189-rotate-array.py
@@ -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