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 62eaa5c commit 97ef058Copy full SHA for 97ef058
merge-k-sorted-lists/Chaedie.py
@@ -0,0 +1,27 @@
1
+"""
2
+Solution:
3
+ 1) 모든 linked list 의 value 를 arr에 담는다.
4
+ 2) arr 를 정렬한다.
5
+ 3) arr 로 linked list 를 만든다.
6
+
7
+Time: O(n log(n)) = O(n) arr 만들기 + O(n log(n)) 정렬하기 + O(n) linked list 만들기
8
+Space: O(n)
9
10
11
12
+class Solution:
13
+ def mergeKLists(self, lists: List[Optional[ListNode]]) -> Optional[ListNode]:
14
+ arr = []
15
+ for linked_list in lists:
16
+ while linked_list:
17
+ arr.append(linked_list.val)
18
+ linked_list = linked_list.next
19
20
+ dummy = ListNode()
21
+ node = dummy
22
23
+ arr.sort()
24
+ for num in arr:
25
+ node.next = ListNode(num)
26
+ node = node.next
27
+ return dummy.next
0 commit comments