feat(189-rotate-array): add py3 solution
This commit is contained in:
16
0189_rotate-array/python3/extra_space.py
Normal file
16
0189_rotate-array/python3/extra_space.py
Normal file
@@ -0,0 +1,16 @@
|
||||
# Time: O(N)
|
||||
# Space: O(N)
|
||||
class Solution:
|
||||
def rotate(self, nums: List[int], k: int) -> None:
|
||||
"""
|
||||
Do not return anything, modify nums in-place instead.
|
||||
"""
|
||||
n = len(nums)
|
||||
result = [None] * n
|
||||
|
||||
for i, num in enumerate(nums):
|
||||
new_i = (i + k) % n
|
||||
result[new_i] = num
|
||||
|
||||
for i, num in enumerate(nums):
|
||||
nums[i] = result[i]
|
||||
0
0189_rotate-array/python3/solution.py
Normal file
0
0189_rotate-array/python3/solution.py
Normal file
Reference in New Issue
Block a user