Skip to content

Commit 2bc5898

Browse files
authored
Merge pull request doocs#101 from zhanary/master
Update Solution to 026[python2] - 48ms
2 parents 161fef6 + 88c010e commit 2bc5898

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Definition for singly-linked list.
2+
# class ListNode(object):
3+
# def __init__(self, x):
4+
# self.val = x
5+
# self.next = None
6+
7+
#经典的merge,每次都比较两个链表的第一个数字
8+
#递归的方法
9+
class Solution(object):
10+
def mergeTwoLists(self, l1, l2):
11+
if not l1 or not l2:
12+
return l1 or l2
13+
if l1.val < l2.val: #输出较小的一个
14+
l1.next = self.mergeTwoLists(l1.next, l2)
15+
return l1
16+
else :
17+
l2.next = self.mergeTwoLists(l1, l2.next)
18+
return l2
19+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#48ms
2+
class Solution(object):
3+
def removeDuplicates(self, nums):
4+
if not nums:
5+
return 0
6+
7+
newtail = 0
8+
9+
for i in range(1, len(nums)):
10+
if nums[i] != nums[newtail]:
11+
newtail += 1
12+
nums[newtail] = nums[i] #只要求字符串前段正确即可
13+
14+
return newtail + 1 #要求返回新字符串长度

0 commit comments

Comments
 (0)