189.Rotate Array

class Solution:
    def rotate(self, nums: List[int], k: int) -> None:
        """
        Do not return anything, modify nums in-place instead.
        """
        lenList = len(nums)
        while k > lenList:
            k = k % lenList
        rp = lenList - 1
        nums_tmp = []
        for i in range(k):
            nums_tmp.append(nums[lenList-k+i])
        while rp > k-1 :
            nums[rp] = nums[rp-k]
            rp -= 1
        for j in range(k):
            nums[j] = nums_tmp[j]
原文地址:https://www.cnblogs.com/luo-c/p/12857425.html