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]

 

posted @ 2020-05-09 14:51  星海寻梦233  阅读(75)  评论(0编辑  收藏  举报