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 9984366 commit 0b89fccCopy full SHA for 0b89fcc
merge-two-sorted-lists/sejineer.py
@@ -0,0 +1,20 @@
1
+"""
2
+시간 복잡도: O(n + m)
3
+공간 복잡도: O(1)
4
5
+class Solution:
6
+ def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]:
7
+ node = ListNode(0)
8
+ head = node
9
+
10
+ while list1 and list2:
11
+ if list1.val <= list2.val:
12
+ head.next = list1
13
+ list1 = list1.next
14
+ else:
15
+ head.next = list2
16
+ list2 = list2.next
17
+ head = head.next
18
+ head.next = list1 if list1 else list2
19
20
+ return node.next
0 commit comments