189. 旋转数组
代码一: 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 来源: oschina 链接: https://my.oschina.net/u/4305580/blog/3300079