题目:
题解:
def reverse(nums: List[int], left, right) -> None:i, j = left, rightwhile i < j:nums[i], nums[j] = nums[j], nums[i]i+=1j-=1
class Solution:def rotate(self, nums: List[int], k: int) -> None:n = len(nums)k %= nreverse(nums, 0, n - 1)reverse(nums, 0, k - 1)reverse(nums, k, n - 1)