2-line python solution,easy to understand

  • 0

    len(nums) times of rotate turns the list to original,k %= len(nums) is the effective rotate time

    def rotate(self, nums, k):
            k %= len(nums)
            nums[:] = nums[-k:]+nums[:-k]

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.