3: 旋转数组(python)


class Solution(object):
    def rotate(self, nums, k):
        """
        :type nums: List[int]
        :type k: int
        :rtype: None Do not return anything, modify nums in-place instead.
        """
        nums[:] = nums[len(nums) - k:] + nums[:len(nums) - k]  //切成两块再重新组合

猜你喜欢

转载自blog.csdn.net/qq_38013105/article/details/88776221