class Solution:
    def deleteDuplicates(self, head: ListNode) -> ListNode:
        if not head:
            return head
        cur1 = head
        newlist = ListNode(2**31)

        cur2 = newlist
        tmp = head.val
        while cur1 != None:
            if cur2.val == cur1.val:
                cur1 = cur1.next
            else:
                cur2.next = ListNode(cur1.val)
                cur2 = cur2.next
                cur1 = cur1.next
        # print(newlist)
        return newlist.next


# @lc code=end

    tests = [
        (makeListNode([1,1,2]), makeListNode([1,2])),
        (makeListNode([1,1,2,3,3]), makeListNode([1,2,3])),
        (makeListNode([]), makeListNode([]))
    ]
class Solution:
    def numToList(self, num):
        a = None
        cur = None
        for i in str(num)[::-1]:
            tmp = ListNode(int(i))
            tmp.next = None
            if not a:
                a = tmp
                cur = a
            else:
                cur.next = tmp
                cur = cur.next
        return a

    def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
        m = 0
        for tmp in [l1, l2]:
            i = 0
            while True:
                # print(tmp.val)
                m = m + tmp.val * (10**i)
                if tmp.next:
                    i += 1
                    tmp = tmp.next
                else:
                    break
        # print(m)
        # print(self.numToList(m))
        return self.numToList(m)

# @lc code=end

    tests = [
        (makeListNode([2, 4, 3]), makeListNode([5, 6,
                                                4]), makeListNode([7, 0, 8])),
        (makeListNode([8, 5, 3]), makeListNode([2, 4,
                                                4]), makeListNode([0, 0, 8])),
    ]
def test_make_eq():
    assert makeListNode([2]) != makeListNode([3])

    assert makeListNode([2, 4, 3]) == makeListNode([2, 4, 3])
    assert makeListNode([2, 4, 3]) != makeListNode([2, 4, 3, 4])
    assert makeListNode([1, 4, 3]) != makeListNode([2, 4, 3, 4])
def test_str():
    assert str(makeListNode([2, 4, 3])) == '->2->4->3'
class Solution:
    def mergeTwoListsFirst(self, l1: ListNode, l2: ListNode) -> ListNode:
        newList = ListNode(0)
        cur = newList
        cur1 = l1
        cur2 = l2
        while cur1 or cur2:
            tmp = ListNode(0)
            tmp.next = None

            if not cur1:
                tmp.val = cur2.val
                cur2 = cur2.next
            elif not cur2:
                tmp.val = cur1.val
                cur1 = cur1.next

            elif cur1.val < cur2.val:
                tmp.val = cur1.val
                cur1 = cur1.next

            else:
                tmp.val = cur2.val
                cur2 = cur2.next

            cur.next = tmp
            cur = cur.next

        return newList.next

    def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:
        l3 = ListNode(0)
        first = l1
        second = l2
        head = l3
        cur = head
        tmp_val = None
        while first and second:

            if first.val < second.val:
                tmp_val = first.val
                first = first.next
            else:
                tmp_val = second.val
                second = second.next
            tmp = ListNode(tmp_val)
            cur.next = tmp
            cur = cur.next

        # 两个链表如果长度不一样,则剩下一个
        if first:
            cur.next = first
        if second:
            cur.next = second
        return head.next
# @lc code=end

    tests = [
        (makeListNode([1, 2, 4]), makeListNode([1, 3, 4]),
         makeListNode([1, 1, 2, 3, 4, 4])),
    ]