Rotate Array
Question
Example:
Hint
Answer
solution:
class Solution:
# @param nums, a list of integer
# @param k, num of steps
# @return nothing, please modify the nums list in-place.
def rotate(self, nums, k):
if not nums or not k:
return None
n = len(nums)
k = k % n
if k:
nums[:k], nums[k:] = nums[-k:], nums[:-k] #交换两段数据,注意这种用法,不要顾忌不使用第三方会影响数据保存Knowledge:
Last updated