0

I was solving the following question on leetcode.com "189. Rotate Array" and some of the discussion solutions involved the following syntax:

k = k % len(nums) 

what does it mean?

# example:
nums = [1,2]
k = 3
def rotate(self, nums: List[int], k: int) -> None:
    k = k % len(nums)
    if len(nums) <= 1 or k == 0:
        return
    else:
        nums[:] = nums[-k:]+nums[:-k]

Output: [2,1]

0 Answers0