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 00458c7 commit fe47f3aCopy full SHA for fe47f3a
merge-two-sorted-lists/kayden.py
@@ -0,0 +1,23 @@
1
+class Solution:
2
+ # 시간복잡도: O(N+M) list1:N, list2: M
3
+ # 공간복잡도: O(N+M)
4
+ def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]:
5
+ merged = ListNode()
6
+ cur = merged
7
+
8
+ while list1 and list2:
9
+ if list1.val < list2.val:
10
+ cur.next = list1
11
+ list1 = list1.next
12
+ else:
13
+ cur.next = list2
14
+ list2 = list2.next
15
+ temp = temp.next
16
17
+ if list1:
18
19
20
+ if list2:
21
22
23
+ return merged.next
0 commit comments