Skip to content

Commit bd41935

Browse files
authored
Merge pull request #3 from chakyam/master
Update solution 021 [Python3]
2 parents d5396b9 + 0dc39c1 commit bd41935

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Definition for singly-linked list.
2+
# class ListNode:
3+
# def __init__(self, x):
4+
# self.val = x
5+
# self.next = None
6+
7+
class Solution:
8+
def mergeTwoLists(self, l1, l2):
9+
"""
10+
:type l1: ListNode
11+
:type l2: ListNode
12+
:rtype: ListNode
13+
"""
14+
while l1 and l2:
15+
if l1.val < l2.val:
16+
l1.next=self.mergeTwoLists(l1.next,l2)
17+
return l1
18+
else:
19+
l2.next=self.mergeTwoLists(l1,l2.next)
20+
return l2
21+
return l1 or l2

0 commit comments

Comments
 (0)