leetcode 1288. Remove Covered Intervals(去掉重叠的区间)

[算法][面试]开源一下我的python板子:前缀和、差分数组、线段树、树状数组 关于区间查询和修改问题,开源一下我的四个板子,根据不同的复杂度,适用于不同的场景。其中,所有的板子都封装成一个类,开箱即用;在性能上,如树状数组不必手敲的C-like数组板子效率高,但好就好在拿来就用不需要考虑变量名啥的,并且API尽量做到统一。 阅读详情

Given an array intervals where intervals[i] = [li, ri] represent the interval [li, ri), remove all intervals that are covered by another interval in the list.

The interval [a, b) is covered by the interval [c, d) if and only if c <= a and b <= d.

Return the number of remaining intervals.

Example 1:

Input: intervals = [[1,4],[3,6],[2,8]]
Output: 2
Explanation: Interval [3,6] is covered by [2,8], therefore it is removed.
Example 2:

Input: intervals = [[1,4],[2,3]]
Output: 1

给出二维数组,里面每一个元素都是一个区间,返回一共有多少个不重叠的区间。
区间重叠是指起点和终点覆盖了另一个区间。

思路:
因为区间重叠是指
The interval [a, b) is covered by the interval [c, d) if and only if c <= a and b <= d.
按区间的起点大小排序,这样就满足了c <= a,只需要看终点b <= d
当然终点要从大往小看,因为先看大的,后面的比它小,就是在一个区间里。遇见比当前大的终点,就说明是一个新的区间。

    public int removeCoveredIntervals(int[][] intervals) {
        int result = 0;
        int end = -1;
        int n = intervals.length;
        
        //按起点大小升序排序,如果起点大小相同,按终点降序排序
        Arrays.sort(intervals, (o1, o2)->o1[0] == o2[0] ? o2[1] - o1[1] : o1[0] - o2[0]);
        
        for(int[] interval : intervals) {
            if(end < interval[1]) {
                result ++;
                end = interval[1];
            }
        }
        return result;
    }
统信UOS系统盘扩容保姆级教程:用GParten-分区编辑器5分钟搞定 本文提供统信UOS系统盘扩容的详细图形化教程。针对系统盘空间不足问题,重点介绍如何使用系统自带的GParten-分区编辑器,在5-10分钟内安全、直观地完成扩容操作,无需记忆复杂命令,适合所有用户快速解决存储空间告急的困扰。 阅读详情

相关推荐

Leetcode435:删除重叠区间(python)

贪心策略:优先保留结尾小且不相交的区间 实现方法:先对区间结尾进行从小到大的排序,确保后一个区间的首大于前一个区间的尾,保留,计数加一 class Solution(object): def eraseOverLapIntervals(self,intervals): if not intervals: return 0 nums = sorted(intervals,key=lambda x:x[1])#按照每一个区间的末尾进行排序

weixin_42491368的博客 1292

FPGA矩阵键盘计算器Verilog实现与Quartus仿真全流程解析

本文详细解析了基于FPGA和Verilog的矩阵键盘计算器实现全流程,包括矩阵键盘扫描、状态机设计、算术运算逻辑及数码管显示驱动。通过Quartus仿真与Testbench测试,确保设计稳定性与准确性,适合数字逻辑设计初学者学习FPGA开发与硬件描述语言应用。

chair的专栏 742

Leetcode第1288题 删除被覆盖区间C++解法

跟435题一样,都是先排序。 class Solution { public: int removeCoveredIntervals(vector<vector<int>>& intervals) { int size=intervals.size(); if(size<2) return 0; sort(intervals.begin(),intervals.end(),[] (const auto&

梅杏柿的博客 172

power bi 演唱会-佐罗

我是业务分析人员,注重使用性,因此,课程不到 30% 的内容就可以解决目前为止我碰到的所有业务问题,剩下的 70% 内容是帮助我提升,优化,升华,精益求精用的,比如第三方工具,比如代码运行速度优化,比如查询逻辑优化等等。系统性上来说,结构明晰,安排上非常有条理,层层递进;《BI 真经》,中有真经二字,略显夸大,而当我第一次证明了这点的时候,我也非常惊讶,这就是我做以下所有事情的一切动力。《BI 真经》综合考量思想性,系统性,本质性,创新性,通用性,技巧性,启发性,对比其他课程有压倒性的显著优势。

v_1090213742的博客 911

【正点原子STM32连载】第六十章 串口IAP实战:从Bootloader到APP的无缝升级

本文以正点原子STM32F103开发板为例,详细讲解了串口IAP(在应用编程)技术的实现原理与实战步骤。内容涵盖Bootloader与APP的分工、FLASH空间规划、核心代码解析以及Ymodem协议的应用,旨在帮助开发者掌握通过串口为嵌入式设备实现远程固件升级的关键技术,提升产品维护与迭代效率。

weixin_29161719的博客 444

Leetcode.1288. 删除被覆盖区间

Leetcode.1288. 删除被覆盖区间

kitesxian的博客 473

信号编辑软件ZX/SignalEditing

信号编辑软件ZX/SignalEditing

weixin_45661395的博客 955

1288. 删除被覆盖区间

1288. 删除被覆盖区间

Rolle的博客 363

MicroPython学习:在STM32上进行移植

本文将介绍如何在STM32上移植MicroPython,并提供相应的源代码。通过以上步骤,你已经成功地将MicroPython移植到STM32上,并可以使用MicroPython语言编写和运行代码。你可以进一步探索MicroPython的功能和API,以利用STM32的各种外设和功能。使用STM32CubeProgrammer或其他适当的烧录工具,将编译生成的MicroPython固件烧录到STM32微控制器中。打开该文件,并根据你的STM32微控制器类型进行必要的配置更改。模块来控制STM32的LED。

JeeVue的博客 1237

多智能体系统在AI物流优化中的实际应用案例

订单波峰波谷难应对(如双11订单量暴增300%);动态干扰难处理(如突发交通拥堵、客户临时改地址);全局优化难实现(单辆车最优≠整体最优)。本文聚焦“多智能体系统(MAS)”这一AI技术,讲解其如何通过“群体智能”破解物流调度难题,并结合实际案例展示落地效果。本文从“生活故事→核心概念→技术原理→实战案例→未来趋势”逐步展开,用“快递员团队协作送外卖”类比MAS运作,结合Python代码模拟任务分配,最后通过某物流企业的真实项目验证效果。

AIGC应用创新大全的博客 1630

Leetcode 1288. Remove Covered Intervals(容易理解的解法)

Leetcode 1288. Remove Covered Intervals 题目链接: Remove Covered Intervals 难度:Medium 题目大意: 给出若干个区间的范围,如果一个区间包含于其他区间,则将该区间删除,判断最后还剩多少个区间。 思路: 将区间按照左值从小到大排列,然后遍历这些区间,进行判断。用到双指针。 代码 class Solution { public int removeCoveredIntervals(int[][] intervals) {

xue1236的博客 275

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

leetcode 1288. Remove Covered Intervals

Given an array intervals where intervals[i] = [li, ri] represent the interval [li, ri), remove all intervals that are covered by another interval in the list. The interval [a, b) is covered by the interval [c, d) if and only if c <= a and b <= d. Ret

jmhIcoding 525

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

leetcode435:区间去掉不重叠

/*题目描述: 给定多个区间,计算让这些区间互不重叠所需要移除区间的最少个数。起止相连不算重叠。 示例: 输入是一个数组,数组由多个长度固定为2的数组组成,表示区间的开始和结尾,输出一个整数, 表示需要移除的区间数量。 Input:[[1,2],[2,4],[1,3]] Output:1 在示例中,可以移除区间[1,3],使得剩余的区间[[1,2],[2,4]]互不重叠。 解题思路: 在选择要保留区间时,区间的结尾十分重要:选择的区间结尾越小,余留给其他区间的空间就越大, 就越能保留更多的区间。因此,.

Jiangtagong的博客 711

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

【leetcode】区间问题求解:重叠区间,合并区间,删除区间

区间问题: 这类面试题目还挺讨巧的,因为不需要掌握什么数据结构与算法的先验知识,看懂题目之后模拟一遍即可,很容易考察出应聘者到底会不会写代码。 文章目录56. 合并区间1. 题目描述2. 思路分析3. 参考代码57. 插入区间1. 题目描述2. 思路分析3. 参考代码1288. 删除被覆盖区间1. 题目描述2. 思路分析3. 参考代码228. 汇总区间1. 题目描述2. 思路分析3. 参考代码354. 俄罗斯套娃信封问题1. 题目描述2. 思路分析3. 参考代码 56. 合并区间 1. 题目描述 leetc

小朱小朱绝不认输的博客 1300

【Leetcode】1288. Remove Covered Intervals

题目地址: https://leetcode.com/problems/remove-covered-intervals/ 给定nnn个闭区间,所有区间左端点非负,并且区间两两不同。先删去所有被包含在某另一个区间的区间,问剩下多少个区间。 将所有区间按照左端点从小到大排序,若左端点相同则按右端点从大到小排序。接下来遍历区间,并且维护一个变量,为已经遍历过的区间的最大右端点。如果遇到某个区间的右端点不大于该变量,说明该区间可以被覆盖,略过;否则计数加111,并更新该变量。代码如下: import java.u

数学、算法爱好者的博客 384

leetcode1288. 删除被覆盖区间

解题思路 按照左端点升序右端点降序的顺序先排序 在判断情况 1.覆盖 2.相交 3.无交点 代码 class Solution { public int removeCoveredIntervals(int[][] intervals) { List<int[]> arrList = new ArrayList<>(); int n = intervals.length; for(int i=0;i<n;i++){

weixin_45221477的博客 176

leetcode 1288. 删除被覆盖区间-区间覆盖问题

解题思路: 本题要求左右都有端点全部被某一个子区间覆盖才认为是覆盖掉,所以要考虑左右端点问题,为了简化问题,可以先进行排序,然后再进行判断 排序: 1.排序方式:按照左端点升序排序,当左端点相同时按照右端点降序排序 2.排序目的:排序后所有子区间成类阶梯状排列,此时不需要考虑左端点是否在覆盖区间内,简化比较复杂度 方法一:逆向思维,找到需要被删除的个数,判断是覆盖 class Solution { public: int removeCoveredIntervals(vector<v..

jhb1021821368的博客 303

LeetCode 1272. 删除区间

文章目录1. 题目2. 解题 1. 题目 给你一个 有序的 不相交区间列表 intervals 和一个要删除的区间 toBeRemoved, intervals 中的每一个区间 intervals[i] = [a, b] 都表示满足 a <= x < b 的所有实数 x 的集合。 我们将 intervals 中任意区间与 toBeRemoved 有交集的部分都删除。 返回删除所有交集区间后, intervals 剩余部分的 有序 列表。 示例 1: 输入:intervals = [[0,2],

Michael是个半路程序员 1229

Leetcode 1288.删除被覆盖区间(Remove Covered Intervals)

Leetcode 1288.删除被覆盖区间 1 题目描述(Leetcode题目链接)   给你一个区间列表,请你删除列表中被其他区间所覆盖的区间。 只有当 c <= a 且 b <= d 时,我们才认为区间 [a,b) 被区间 [c,d) 覆盖。 在完成所有删除操作后,请你返回列表中剩余区间的数目。 输入:intervals = [[1,4],[3,6],[2,8]] 输出:2 解释:...

qq_39378221的博客 332

【LeetCode-算法】57. 插入区间(Java实现)

题目 给出一个无重叠的 ,按照区间起始端点排序的区间列表。在列表中插入一个新的区间,你需要确保列表中的区间仍然有序且不重叠(如果有必要的话,可以合并区间)。 示例1 输入: intervals = [[1,3],[6,9]], newInterval = [2,5] 输出: [[1,5],[6,9]] 示例2 输入: intervals = [[1,2],[3,5],[6,7],[8,10],[...

sinat_35050808的博客 726

Leetcode 1288:删除被覆盖区间(超详细的解法!!!)

给你一个区间列表,请你删除列表中被其他区间所覆盖的区间。 只有当 c <= a 且 b <= d 时,我们才认为区间 [a,b) 被区间 [c,d) 覆盖。 在完成所有删除操作后,请你返回列表中剩余区间的数目。 示例: 输入:intervals = [[1,4],[3,6],[2,8]] 输出:2 解释:区间 [3,6] 被区间 [2,8] 覆盖,所以它被删除了。 提示: 1 &...

coordinate的博客 1312

Leetcode:1288. 删除被覆盖区间(贪心算法)

1288. 删除被覆盖区间 难度中等20收藏分享切换为英文接收动态反馈 给你一个区间列表,请你删除列表中被其他区间所覆盖的区间。 只有当c <= a且b <= d时,我们才认为区间[a,b)被区间[c,d)覆盖。 在完成所有删除操作后,请你返回列表中剩余区间的数目。 示例: 输入:intervals = [[1,4],[3,6],[2,8]] 输出:2 解释:区间 [3,6] 被区间 [2,8] 覆盖,所以它被删除了。 提示:​​​​​​ 1 &l...

stackempty2的博客 430

LeetCode 1288. 删除被覆盖区间(lambda排序)

1. 题目 给你一个区间列表,请你删除列表中被其他区间所覆盖的区间。 只有当 c <= a 且 b <= d 时,我们才认为区间 [a,b) 被区间 [c,d) 覆盖。 在完成所有删除操作后,请你返回列表中剩余区间的数目。 示例: 输入:intervals = [[1,4],[3,6],[2,8]] 输出:2 解释:区间 [3,6] 被区间 [2,8] 覆盖,所以它被删除了。 提示:...

Michael是个半路程序员 1518

LeetCode-1288. Remove Covered Intervals

Given a list of intervals, remove all intervals that are covered by another interval in the list.Interval[a,b)is covered byinterval[c,d)if and only ifc <= aandb <= d. After doing so, r...

reigns的博客 382

1288. Remove Covered Intervals**

1288. Remove Covered Intervals** https://leetcode.com/problems/remove-covered-intervals/ 题目描述 Given a list of intervals, remove all intervals that are covered by another interval in the list. Interval...

珍妮的选择的博客 725
上一篇: java 自定义Comparator排序 lambda表达式
下一篇: leetcode 169. Majority Element(大多数的元素)
蓝羽飞鸟
博客等级 码龄8年 1万+粉丝 727原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蓝羽飞鸟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值