class Solution:
def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:
rlt = ListNode(0)
tmp = rlt
while l1 or l2:
if not l1:
tmp.next = l2
break
if not l2:
tmp.next = l1
break
if l1.val < l2.val:
tmp.next = l1
l1 = l1.next
else:
tmp.next = l2
l2 = l2.next
tmp = tmp.next
return rlt.next
21,合并两个有序链表
最新推荐文章于 2024-04-26 17:02:36 发布