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 7e53ec1 commit f056ea5Copy full SHA for f056ea5
merge-two-sorted-lists/wozlsla.py
@@ -0,0 +1,28 @@
1
+"""
2
+# Intuition
3
+-
4
+# Approach
5
6
7
+
8
+# Definition for singly-linked list.
9
+# class ListNode:
10
+# def __init__(self, val=0, next=None):
11
+# self.val = val
12
+# self.next = next
13
14
15
+class Solution:
16
+ def mergeTwoLists(
17
+ self, list1: Optional[ListNode], list2: Optional[ListNode]
18
+ ) -> Optional[ListNode]:
19
20
+ if not (list1 and list2):
21
+ return list1 or list2
22
23
+ if list1.val < list2.val:
24
+ list1.next = self.mergeTwoLists(list1.next, list2)
25
+ return list1
26
+ else:
27
+ list2.next = self.mergeTwoLists(list1, list2.next)
28
+ return list2
0 commit comments