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