이름
두 사람은 새로운 정렬 된 목록 및 반환에 목록을 명령했다. 새로운 목록은 두 목록으로 구성 주어진 모자이크의 모든 노드입니다.
문제 해결
class Solution:
def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:
prehead = ListNode(-1)
prev = prehead
while l1 and l2:
if l1.val <= l2.val:
prev.next = l1
l1 = l1.next
else:
prev.next = l2
l2 = l2.next
prev = prev.next
# exactly one of l1 and l2 can be non-null at this point, so connect
# the non-null list to the end of the merged list.
prev.next = l1 if l1 is not None else l2
return prehead.next
저자 : LeetCode의
링크 : HTTPS : //leetcode-cn.com/problems/merge-two-sorted-lists/solution/he-bing-liang-ge-you-xu-lian-biao-by-leetcode/
출처 : 힘 버클 (LeetCode)
의 저작권은 저자에 의해 소유. 상업 무단 전재 공인 저자에 문의하시기 바랍니다, 소스가 표시 비상업적 무단 전재하시기 바랍니다.