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 f978922 commit 161edccCopy full SHA for 161edcc
merge-two-sorted-lists/doh6077.py
@@ -0,0 +1,17 @@
1
+
2
+# 21. Merge Two Sorted Lists
3
4
+class Solution:
5
+ def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]:
6
+ tempNode = ListNode()
7
+ node = tempNode
8
+ while list1 and list2:
9
+ if list1.val < list2.val:
10
+ node.next = list1
11
+ list1 = list1.next
12
+ else:
13
+ node.next = list2
14
+ list2 = list2.next
15
+ node = node.next
16
+ node.next = list1 or list2
17
+ return tempNode.next
0 commit comments