Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit fcf6841

Browse files
Create Merge Two Sorted Lists.py
1 parent b89bd39 commit fcf6841

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Definition for singly-linked list.
2+
# class ListNode:
3+
# def __init__(self, val=0, next=None):
4+
# self.val = val
5+
# self.next = next
6+
class Solution:
7+
def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:
8+
9+
if not l1 or not l2:
10+
return l1 or l2
11+
12+
if l1.val < l2.val:
13+
l1.next = self.mergeTwoLists(l1.next, l2)
14+
return l1
15+
16+
else:
17+
l2.next = self.mergeTwoLists(l1, l2.next)
18+
return l2

0 commit comments

Comments
 (0)