Offer 25. 合并两个排序的链表
1. python
class Solution:
def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:
cur = tmpHead =ListNode(0) #此处注意, 指向同一个头节点
while (l1 and l2):
if l1.val<l2.val:
cur.next,l1=l1,l1.next
else:
cur.next,l2=l2,l2.next
cur=cur.next
cur.next=l1 if l1 else l2 #此处包含了l1或者l2为空的情况了
return tmpHead.next