Skip to content

Commit 3e8f1a2

Browse files
committed
Moved the original solution to the top and the new one to the bottom.
1 parent cb95cde commit 3e8f1a2

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

Diff for: python/0021-merge-two-sorted-lists.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@
44
# self.val = val
55
# self.next = next
66

7-
# Recursive
8-
class Solution:
9-
def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]:
10-
if not list1:
11-
return list2
12-
if not list2:
13-
return list1
14-
lil, big = (list1, list2) if list1.val < list2.val else (list2, list1)
15-
lil.next = self.mergeTwoLists(lil.next, big)
16-
return lil
17-
187
# Iterative
198
class Solution:
209
def mergeTwoLists(self, list1: ListNode, list2: ListNode) -> ListNode:
@@ -32,3 +21,14 @@ def mergeTwoLists(self, list1: ListNode, list2: ListNode) -> ListNode:
3221
node.next = list1 or list2
3322

3423
return dummy.next
24+
25+
# Recursive
26+
class Solution:
27+
def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]:
28+
if not list1:
29+
return list2
30+
if not list2:
31+
return list1
32+
lil, big = (list1, list2) if list1.val < list2.val else (list2, list1)
33+
lil.next = self.mergeTwoLists(lil.next, big)
34+
return lil

0 commit comments

Comments
 (0)