就像一个贪吃蛇将两个链表一一的吃进来
class Solution(object):
def mergeTwoLists(self, list1, list2):
"""
:type list1: Optional[ListNode]
:type list2: Optional[ListNode]
:rtype: Optional[ListNode]
"""
p = ListNode(0)
cur = p
while list1 and list2:
if list1.val >= list2.val:
cur.next = list2
list2 = list2.next
cur = cur.next
else:
cur.next = list1
list1 = list1.next
cur = cur.next
if list1 is None:
cur.next = list2
else:
cur.next = list1
# while list1:
# cur.next = list1
# list1 = list1.next
# cur = cur.next
# while list2:
# cur.next = list2
# list2 = list2.next
# cur = cur.next
return p.next