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


  • -1
    C
    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]
            nums.extend(tmp)

  • 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.