Rotate right a list of items in python

Solution

Following is our code.

class Solution: def rotate(self, nums: List[int], k: int) -> None: """ Do not return anything, modify nums in-place instead. """ length = len(nums) k = k%length tempArr = nums[length-k:].copy() for i in range(length-1,k-1,-1): nums[i] = nums[i-k] nums[:k] = tempArr[:k]