1 parent 5704bca commit 941997eCopy full SHA for 941997e
1 file changed
LeetCode/mergeKLists.py
@@ -0,0 +1,24 @@
1
+# Definition for singly-linked list.
2
+# class ListNode(object):
3
+# def __init__(self, x):
4
+# self.val = x
5
+# self.next = None
6
+class Solution(object):
7
+ def mergeKLists(self, lists):
8
+ """
9
+ :type lists: List[ListNode]
10
+ :rtype: ListNode
11
12
+ s = []
13
+ for nodes in lists:
14
+ while nodes:
15
+ s.append(nodes.val)
16
+ nodes = nodes.next
17
+ s.sort()
18
+ Node = ListNode(0)
19
+ curnode = Node
20
+ for i in s:
21
+ node = ListNode(i)
22
+ curnode.next = node
23
+ curnode = curnode.next
24
+ return Node.next
0 commit comments