Skip to content

Commit 941997e

Browse files
committed
committed from zkp
1 parent 5704bca commit 941997e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

LeetCode/mergeKLists.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)