452. 用最少数量的箭引爆气球
python">class Solution:def findMinArrowShots(self, points: List[List[int]]) -> int:points.sort(key=lambda x:x[0])r = points[0][1]cnt = 1for i in points:if i[0] > r:cnt += 1r = i[1]else:r = min(r, i[1])return cnt
有趣,之前做过的。
435. 无重叠区间
python">class Solution:def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int:if not intervals:return 0intervals.sort(key=lambda x: (x[0], x[1]))res = 1r = intervals[0][1]for i in intervals:if i[0] >= r:r = i[1]res += 1else:r = min(i[1], r)return len(intervals) - res
这题和之前的不就一样的吗,不知道答案在那咔咔写个啥。
763. 划分字母区间
python">class Solution:def partitionLabels(self, s: str) -> List[int]:last = {}for i, ch in enumerate(s):last[ch] = ires = []start = 0end = 0for i, ch in enumerate(s):end = max(end, last[ch])if i == end:res.append(end - start + 1)start = i + 1return res
这是很巧妙的想法。