Rotate Array (Leetcode 189)
Problem Link: https://leetcode.com/problems/rotate-array/
class Solution:
def rotate(self, nums: List[int], k: int) -> None:
"""
Do not return anything, modify nums in-place instead.
"""
n=len(nums)
d=n-(k%n)
# nums[:] is used to make changes to the list while
# nums[] just changes the reference to the list
nums[:]=nums[d:]+nums[:d]
Last updated