语言:python数组切片秒了
思路:先切片再拼接
solution:
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.
"""
if k==0:
return
elif k>len(nums):
k=k%len(nums)
print(nums[-k:])
tmp=nums[-k:]+nums[:-k]
print(tmp)
for i in range(len(nums)):
nums[i]=tmp[i]
时间复杂度:O(n)