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