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 904339d commit 783de6aCopy full SHA for 783de6a
merge-two-sorted-lists/printjin-gmailcom.py
@@ -0,0 +1,19 @@
1
+class ListNode:
2
+ def __init__(self, val=0, next=None):
3
+ self.val = val
4
+ self.next = next
5
+
6
+class Solution:
7
+ def mergeTwoLists(self, list1, list2):
8
+ dummy = ListNode()
9
+ current = dummy
10
+ while list1 and list2:
11
+ if list1.val < list2.val:
12
+ current.next = list1
13
+ list1 = list1.next
14
+ else:
15
+ current.next = list2
16
+ list2 = list2.next
17
+ current = current.next
18
+ current.next = list1 if list1 else list2
19
+ return dummy.next
0 commit comments