Rotate right a list of items in python
- Given a list of numbers, rotate right a list by k-steps
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]