当前位置:网站首页>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;
}
};
边栏推荐
- 上半年火灾起数下降27.7%,广东将这样提升全民消防安全素质
- Interaction free shell programming
- go入门篇 (5)
- Go Introduction (2)
- Guangdong's finance has taken many measures to help stabilize the "ballast stone" of food security
- kazoo使用教程
- Could not load dynamic library ‘libcudnn.so.8‘;
- 2021-3-22-directed graph sorting
- 严控室外作业时间!佛山住建局发文:加强高温期间建筑施工安全管理
- Write and read system temporary files: createtempfile and tempfilecontent[easy to understand]
猜你喜欢

STS下载教程(include官网无法下载解决方案)

iptables防火墙

Alibaba cloud RDS exception during pool initialization

LNMP architecture setup (deploy discuz Forum)

Fundamentals of mathematics 02 - sequence limit
![[untitled] multimodal model clip](/img/f0/8ae72ae0845372b6fe2866fae83f52.png)
[untitled] multimodal model clip

解决方案:Can not issue executeUpdate() or executeLargeUpdate() for SELECTs

Watermelon book chapter 3 (first & second)

Shell脚本文本三剑客之awk

Shell script text three swordsmen sed
随机推荐
Check the number of file descriptors opened by each process under the system
Kazoo tutorial
deeplab系列详解(简单实用年度总结)
评价自动化测试优劣的隐性指标
孤独的年轻人,戒不了Jellycat
Sword finger offer note: T39. Numbers that appear more than half of the time in the array
The bank's face recognition system was broken: a depositor was stolen 430000 yuan
53 亿 BI 市场 TOP 10:帆软、微软、永洪、SAP、百度、IBM、SAS、思迈特、Salesforce、浪潮通软
Chapter 7 exception handling
Wechat applet must use interface "suggestions collection"
Alibaba cloud RDS exception during pool initialization
go入门篇 (5)
系统临时文件的写和读:createTempFile和tempFileContent[通俗易懂]
Leetcode 01: t1. sum of two numbers; T1108. IP address invalidation; T344. Reverse string
MySQL paging query instance_ MySQL paging query example explanation "suggestions collection"
I do live e-commerce in tiktok, UK
Go Introduction (2)
Firewall firewall
阿里云云数据库RDS版Exception during pool initialization
Could not load dynamic library ‘libcudnn.so.8‘;