Python solution : O(1) time, O(n) space

  • -1
    class Solution(object):
        def rotate(self, nums, k):
            :type nums: List[int]
            :type k: int
            :rtype: void Do not return anything, modify nums in-place instead.
            l = len(nums)
            k = l - k % l
            tmp = nums[:k]
            del nums[:k]

  • 0

    LOL how can it be O(1) time?

Log in to reply

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