训练营计划更新了,补一下DAY36多出来的两道题
435. 无重叠区间
- 题目链接:435. 无重叠区间
python
class Solution(object):
def eraseOverlapIntervals(self, intervals):
"""
:type intervals: List[List[int]]
:rtype: int
"""
if not intervals:
return 0
intervals.sort(key=lambda x:x[0])
result = 0
for i in range(len(intervals)-1):
if intervals[i][1]>intervals[i+1][0]:
intervals[i+1][1] = min(intervals[i+1][1], intervals[i][1])
result+=1
return result
763.划分字母区间
- 题目链接:763.划分字母区间
python
class Solution(object):
def partitionLabels(self, s):
"""
:type s: str
:rtype: List[int]
"""
last_occur = {}
results = []
start = 0
end = 0
for i, ch in enumerate(s):
last_occur[ch]=i
for i, ch in enumerate(s):
end = max(end, last_occur[ch])
if i==end:
results.append(end-start+1)
start = i+1
return results