题解 | #旋转数组#
旋转数组
https://www.nowcoder.com/practice/e19927a8fd5d477794dac67096862042
class Solution:
def solve(self , n: int, m: int, a: List[int]) -> List[int]:
# write code here
# 先整体反转,再局部反转
if m >= n:
m %= n
a.reverse()
a[:m] = reversed(a[:m])
a[m:] = reversed(a[m:])
return a
def solve(self , n: int, m: int, a: List[int]) -> List[int]:
# write code here
# 先整体反转,再局部反转
if m >= n:
m %= n
a.reverse()
a[:m] = reversed(a[:m])
a[m:] = reversed(a[m:])
return a