Skip to content

Commit c46494a

Browse files
committed
Merge branch 'master' of github.com:yanglbme/leetcode
2 parents f60d636 + bd41935 commit c46494a

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)