代码随想录算法训练营DAY36补| 435. 无重叠区间、 763.划分字母区间

训练营计划更新了,补一下DAY36多出来的两道题

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.划分字母区间

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
相关推荐
珹洺2 分钟前
C++算法竞赛篇:DevC++ 如何进行debug调试
java·c++·算法
呆呆的小鳄鱼40 分钟前
leetcode:冗余连接 II[并查集检查环][节点入度]
算法·leetcode·职场和发展
墨染点香40 分钟前
LeetCode Hot100【6. Z 字形变换】
java·算法·leetcode
沧澜sincerely41 分钟前
排序【各种题型+对应LeetCode习题练习】
算法·leetcode·排序算法
CQ_071241 分钟前
自学力扣:最长连续序列
数据结构·算法·leetcode
弥彦_1 小时前
cf1925B&C
数据结构·算法
YuTaoShao1 小时前
【LeetCode 热题 100】994. 腐烂的橘子——BFS
java·linux·算法·leetcode·宽度优先
Wendy14419 小时前
【线性回归(最小二乘法MSE)】——机器学习
算法·机器学习·线性回归
拾光拾趣录9 小时前
括号生成算法
前端·算法
渣呵10 小时前
求不重叠区间总和最大值
算法