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 nums[:] = nums[-k%len(nums):] + nums[0:-k%len(nums)]
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 while k > 0: 9 nums.insert(0, nums.pop()) 10 k -= 1