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 = list(reversed(nums[:k])) + list(reversed(nums[k:])) nums = list(reversed(nums))
旋转前k个,和后面的数,最后统一旋转,就完成了。