We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 792bfb3 commit 2a57d13Copy full SHA for 2a57d13
solution/023.Merge k Sorted Lists/Solution.py
@@ -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