给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数。
python切片:
class Solution:
def rotate(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: void Do not return anything, modify nums in-place instead.
"""
nums_len = len(nums)
nums[:] = nums[nums_len - k :] + nums[:nums_len - k]