189. 旋转数组
2021-02-09 22:19
标签:mil soft ros 代码 技术 inf image mod com 189. 旋转数组 标签:mil soft ros 代码 技术 inf image mod com 原文地址:https://www.cnblogs.com/panweiwei/p/12748831.html 代码一:
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
上一篇:java神奇问题汇总
下一篇:排序篇--插入排序