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 b8b7c86 commit d7f5d8fCopy full SHA for d7f5d8f
merge-two-sorted-lists/jeldo.py
@@ -0,0 +1,17 @@
1
+class Solution:
2
+ # O(n+m), n = len(list1), m = len(list2)
3
+ def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]:
4
+ head = node = ListNode()
5
+ while list1 and list2:
6
+ if list1.val <= list2.val:
7
+ node.next = list1
8
+ list1 = list1.next
9
+ else:
10
+ node.next = list2
11
+ list2 = list2.next
12
+ node = node.next
13
+ if list1:
14
15
+ if list2:
16
17
+ return head.next
0 commit comments