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 c538722 commit ae67756Copy full SHA for ae67756
merge-two-sorted-lists/mandel-17.py
@@ -0,0 +1,16 @@
1
+from typing import Optional
2
+
3
+class ListNode:
4
+ def __init__(self, val=0, next=None):
5
+ self.val = val
6
+ self.next = next
7
8
+class Solution:
9
+ def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]:
10
+ if (not list1) or (list2 and list1.val > list2.val):
11
+ list1, list2 = list2, list1
12
+ if list1:
13
+ list1.next = self.mergeTwoLists(list1.next, list2)
14
15
+ return list1
16
0 commit comments