Created
March 1, 2024 18:47
-
-
Save mlivingston40/a93aa091ab39486c80a44ba323f1d0ba to your computer and use it in GitHub Desktop.
Merge k sorted lists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Definition for singly-linked list. | |
class ListNode: | |
def __init__(self, val=0, next=None): | |
self.val = val | |
self.next = next | |
class Solution: | |
def mergeKLists(self, lists: List[Optional[ListNode]]) -> List: | |
out_list = [] | |
for l in lists: | |
while l is not None: | |
out_list.append(l.val) | |
l = l.next | |
# sort it in place | |
out_list.sort() | |
return out_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment