Example #1
0
    def merge_two_lists(self, l1, l2):
        node = ListNode(-1)
        start = node

        while l1 is not None and l2 is not None:
            if l1.val <= l2.val:
                node.next = l1
                l1 = l1.next
            else:
                node.next = l2
                l2 = l2.next
            node = node.next

        if l1 is not None:
            node.next = l1

        if l2 is not None:
            node.next = l2

        return start.next
Example #2
0
def parse_line(line):
    groups = re.search(r'(\d+) <-> ([\d,\s]+)', line).groups()
    node = Node(groups[0])
    node.next = set(groups[1].replace(' ', '').split(','))
    return node