Python Solution Timeout


  • 0
    Y

    I don't understand why my solution timeout when assign a new pointer to head, could anyone help me with that?
    class Solution(object):
    def partition(self, head, x):
    """
    :type head: ListNode
    :type x: int
    :rtype: ListNode
    """
    hd1 = head1 = ListNode(0)
    hd2 = head2 = ListNode(0)
    cur = head
    while cur:
    if cur.val < x:
    head1.next = cur
    head1 = head1.next
    if head.val >= x:
    head2.next = cur
    head2=head2.next

            cur = cur.next
        head2.next = None
        head1.next = hd2.next
        return hd1.next

Log in to reply
 

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