-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path21.py
35 lines (26 loc) · 774 Bytes
/
21.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
class Solution:
def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:
if not l1 : return l2
if not l2 : return l1
sumList = []
if l1:
while l1.next:
sumList.append(l1.val)
l1 = l1.next
sumList.append(l1.val)
if l2:
while l2.next:
sumList.append(l2.val)
l2 = l2.next
sumList.append(l2.val)
sumList.sort()
head = ListNode(sumList.pop(0))
curr = head
while sumList:
curr.next = ListNode(sumList.pop(0))
curr = curr.next
return head