Problem
Given an integer array nums, rotate the array to the right by k steps, where k is non-negative.
Algorithm
Reverse the substring, note that k may exceed the list length
Code
class Solution:
def rotate(self, nums: List[int], k: int) -> None:
"""
Do not return anything, modify nums in-place instead.
"""
nLen = len(nums)
k = k % nLen
nums.reverse()
nums[:k] = reversed(nums[:k])
nums[k:] = reversed(nums[k:])