Skip to content

Commit 2a57d13

Browse files
committed
Update solution 023 [Python3]
1 parent 792bfb3 commit 2a57d13

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Definition for singly-linked list.
2+
# class ListNode:
3+
# def __init__(self, x):
4+
# self.val = x
5+
# self.next = None
6+
7+
class Solution:
8+
def mergeKLists(self, lists):
9+
"""
10+
:type lists: List[ListNode]
11+
:rtype: ListNode
12+
"""
13+
list0=[]
14+
for i in lists:
15+
while i:
16+
list0.append(i.val)
17+
i=i.next
18+
if list0==[]:
19+
return []
20+
list0.sort(reverse=True)
21+
ln=ListNode(0)
22+
tmp=ln
23+
while list0:
24+
tmp1=list0.pop()
25+
ln.next=ListNode(tmp1)
26+
ln=ln.next
27+
return tmp.next

0 commit comments

Comments
 (0)