Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2eef7c9

Browse files
committedJun 1, 2025·
Solve : Merge K Sorted Lists
1 parent 2d5a196 commit 2eef7c9

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
 
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from typing import List, Optional
2+
class Solution:
3+
def mergeKLists(self, lists)]:
4+
values = []
5+
for l in lists:
6+
while l:
7+
values.append(l.val)
8+
l = l.next
9+
values.sort()
10+
dummy = ListNode(0)
11+
current = dummy
12+
for val in values:
13+
current.next = ListNode(val)
14+
current = current.next
15+
return dummy.next

0 commit comments

Comments
 (0)
Please sign in to comment.