algorithm notes: leetcode#189 rotate array

Problem


Analysis


Solution


1
2
3
4
5
6
7
8
9
class :
def rotate(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: void Do not return anything, modify nums in-place instead.
"""
k = k % len(nums)
nums[:] = nums[-k:] + nums[:-k]

189. Rotate Array