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