435 无重叠区间
class Solution:
def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int:
if not intervals:
return 0
intervals.sort(key=lambda x:x[1])
n=len(intervals)
r=intervals[0][1]
ret=1
for i in range(1,n):
if intervals[i][0]>=r:
ret+=1
r=intervals[i][1]
return n-ret
763 划分字母区间
class Solution:
def partitionLabels(self, s: str) -> List[int]:
last =[0]*26
for i ,ch in enumerate(s):
last[ord(ch)-ord('a')]=i
p=[]
st=0
ed=0
for i,ch in enumerate(s):
ed=max(ed,last[ord(ch)-ord('a')])
if i == ed:
p.append(ed-st+1)
st=ed+1
return p
56