● 435. 无重叠区间
class Solution:
def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int:
if len(intervals)==1:
return 0
intervals=sorted(intervals,key=lambda x:(x[0],x[1]))
res=0
for i in range(1,len(intervals)):
if intervals[i][0]<intervals[i-1][1]:
intervals[i][1]=min(intervals[i-1][1],intervals[i][1])
res+=1
return res
● 763.划分字母区间
class Solution:
def partitionLabels(self, s: str) -> List[int]:
last_zm={}
for i,ch in enumerate(s):
last_zm[ch]=i
res=[]
start,end=0,0
for i,ch in enumerate(s):
end=max(end,last_zm[ch])
if i==end:
res.append(end-start+1)
start=i+1
return res