We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 4d7221d + 711434b commit 80066e8Copy full SHA for 80066e8
merge-two-sorted-lists/yayyz.py
@@ -0,0 +1,25 @@
1
+# Definition for singly-linked list.
2
+# class ListNode:
3
+# def __init__(self, val=0, next=None):
4
+# self.val = val
5
+# self.next = next
6
+class Solution:
7
+ def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]:
8
+ dummy = ListNode(0)
9
+ current = dummy
10
+
11
+ while list1 is not None and list2 is not None:
12
+ if list1.val < list2.val:
13
+ current.next = list1
14
+ list1 = list1.next
15
+ else:
16
+ current.next = list2
17
+ list2 = list2.next
18
+ current = current.next
19
20
+ if list1 is not None:
21
22
23
24
25
+ return dummy.next
0 commit comments