python TLE


  • 0
    S

    I got TLE with input [1,2,3]. Any idea what did i missing?

    class Solution(object):
    def oddEvenList(self, head):
    """
    :type head: ListNode
    :rtype: ListNode
    """
    if not head: return None
    odd = ListNode(None)
    even = ListNode(None)

        o1, o2 = odd, even
        node, flag = head, 1
        
        while node:
            print(node)
            if flag == 1:
                o1.next = node
                o1 = o1.next
            else:
                o2.next = node
                o2 = o2.next
            flag = flag * -1
            node = node.next
        
        o1.next = even.next
        return odd.next

Log in to reply
 

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