这里卡我的点是,不要return,要改nums的值。我搞了一个新数组res
但是用nums = res不行,用nums = res[:]也不行,用nums[:] = res才可以
不过这一点也不是特别重要
1 class Solution(object): 2 def rotate(self, nums, k): 3 """ 4 :type nums: List[int] 5 :type k: int 6 :rtype: None Do not return anything, modify nums in-place instead. 7 """ 8 length = len(nums) 9 k = k % length 10 res = [] 11 i = length - k 12 while i < length: 13 res.append(nums[i]) 14 i += 1 15 i = 0 16 while i < length - k: 17 res.append(nums[i]) 18 i += 1 19 nums[:] = res