❤leetcode,python2❤给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数。

68 阅读1分钟
class Solution(object):
    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]