题解 | #旋转数组#
旋转数组
https://www.nowcoder.com/practice/e19927a8fd5d477794dac67096862042
class Solution: def solve(self , n: int, m: int, a: List[int]) -> List[int]: def func(i, j): while i < j: a[i], a[j] = a[j], a[i] i += 1 j -= 1 m = m % n # 避免过多的移动 func(0, n-1) # 先整体翻转 func(0, m-1) # 再翻转前m个 func(m, n-1) # 最后反转剩下的 return a