当前位置:网站首页>20210422 consolidation interval
20210422 consolidation interval
2022-07-27 12:18:00 【Anethole job】
In array intervals Represents a set of intervals , The single interval is intervals[i] = [starti, endi] . Please merge all overlapping intervals , And return a non overlapping interval array , The array needs to cover exactly all the intervals in the input .
Example 1:
Input :intervals = [[1,3],[2,6],[8,10],[15,18]]
Output :[[1,6],[8,10],[15,18]]
explain : Section [1,3] and [2,6] overlap , Combine them into [1,6].
Example 2:
Input :intervals = [[1,4],[4,5]]
Output :[[1,5]]
explain : Section [1,4] and [4,5] Can be regarded as overlapping interval .
class Solution {
public:
vector<vector<int>> merge(vector<vector<int>>& intervals) {
vector<vector<int>> ans;
int m = intervals.size();
if(m == 0)
{
return ans;
}
for(int i = 0; i < m; i++)
{
int L = intervals[i][0];
int R = intervals[i][0];
if(!ans.size() || ans.back()[1] < L)
{
ans.push_back({
L,R});
}
else
{
ans.back()[1] = max(ans.back()[1], R);
}
}
return ans;
}
};
边栏推荐
- Fundamentals of mathematics 01
- Mysql8msi installation tutorial (database mysql installation tutorial)
- 解决@OneToMany查询陷入循环引用问题
- 查看系统下各个进程打开的文件描述符数量
- Shutter project scrollcontroller attached to multiple scroll views, failed assertion: line 109 POS 12 error handling
- Wilcoxon rank sum and signed rank
- go 用本地代码replace
- Newticker uses
- About the problem that the onapplicationevent method of the custom listener is executed multiple times
- V-show failure
猜你喜欢

Solution: can not issue executeupdate() or executelargeupdate() for selections

I do live e-commerce in tiktok, UK

Shell脚本文本三剑客之awk

Multi activity disaster recovery construction after station B 713 accident | takintalks share

解决@OneToMany查询陷入循环引用问题

npm踩坑

2021-3-22-directed graph sorting

Go Beginner (4)

How to make a graph? Multiple subgraphs in a graph are histogram (or other graphs)

Go replace with local code
随机推荐
Go replace with local code
Shell script text three swordsman awk
Could not load dynamic library ‘libcudnn.so.8‘;
V-show失效问题
Sword finger offer notes: t57 - I. and two numbers of S
Plus SBOM: assembly line BOM pbom
Docker MySQL Usage Note
Chapter 8 multithreading
iptables防火墙
Guangdong's finance has taken many measures to help stabilize the "ballast stone" of food security
JS-寄生组合式继承
Do you really understand the underlying data structure skip list of Zset in redis?
Chapter 10 enumeration classes and annotations
TapNet: Multivariate Time Series Classification with Attentional Prototypical Network
Principle, concept and construction process of MySQL database master-slave replication cluster
Regular expression of shell programming (grep of shell script text three swordsmen)
Fundamentals of mathematics 02 - sequence limit
When the script runs in the background, it redirects the log from the console to its own named file
Makefile template
Synchronous use reference of the new version of data warehouse (for beginners)