python simple swapping solution O(n)


  • 0
    M
        right = k % len(nums)
        left = len(nums) - right
        i = 0
    
        while left > 0 and right != 0:
            right_i = len(nums) - right
            while right_i < len(nums):
                nums[i], nums[right_i] = nums[right_i], nums[i]
                right_i += 1
                i += 1
            if left > right:
                left -= right
            else:
                right = right % left
                left = left - right

Log in to reply
 

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