[LeetCode] 189. Rotate Array

无敌的切片他又来了。

class Solution:
    def rotate(self, nums: List[int], k: int) -> None:
        """
        Do not return anything, modify nums in-place instead.
        """
        #0
        if k ==0:
            pass
        #else
        lenn = len(nums)
        k = k % lenn
        nums[:] =nums[lenn -k:] + nums[:lenn -k]

image

posted @ 2024-07-01 16:22  夜歌乘年少  阅读(2)  评论(0编辑  收藏  举报