当前位置:网站首页>Leetcode56. consolidation interval
Leetcode56. consolidation interval
2022-06-28 21:05:00 【Yuyy】
This paper is finally updated at 484 Days ago, , The information may have developed or changed .
One 、 Ideas
adopt drawing Looking for a regular Interval problem first Sort
Two 、 problem
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 .Tips :
1 <= intervals.length <= 104intervals[i].length == 20 <= starti <= endi <= 104
Related Topics
- Sort
- Array
\n
- 813
- 0
3、 ... and 、 Code
public int[][] merge(int[][] intervals) {
Arrays.sort(intervals, (o1, o2) -> {
return o1[0] == o2[0] ? o2[1] - o1[1] : o1[0] - o2[0];
});
int start = intervals[0][0];
int end = intervals[0][1];
int[][] result = new int[intervals.length][2];
ArrayList<int[]> ans = new ArrayList<>();
for (int i = 0; i < intervals.length; i++) {
if (intervals[i][0] > end) {
ans.add(new int[]{start, end});
start = intervals[i][0];
end = intervals[i][1];
} else if (intervals[i][1] > end) {
end = intervals[i][1];
}
}
ans.add(new int[]{start, end});
return ans.toArray(new int[ans.size()][]);
}Post Views: 213
边栏推荐
- Understanding of incomplete types
- Bitbucket 使用 SSH 拉取仓库失败的问题
- 精通数据分析能力,收入翻倍?什么才是最强竞争力
- Leetcode daily question - 30 Concatenate substrings of all words
- Is the rapid SSL wildcard certificate genuine in 1981
- resilience4j 重试源码分析以及重试指标采集
- LeetCode986. 区间列表的交集
- 学习太极创客 — MQTT 第二章(八)ESP8266 MQTT 用户密码认证
- The principle and source code analysis of Lucene index construction
- 应用实践 | 10 亿数据秒级关联,货拉拉基于 Apache Doris 的 OLAP 体系演进(附 PPT 下载)
猜你喜欢

ref属性,props配置,mixin混入,插件,scoped样式

什么是接口?什么是接口测试?

视频号如何下载视频?来看超简单方法!

Alibaba cloud MSE full link grayscale solution practice based on Apache apisik

Visualization of neural network structure in different frames

How do I download videos? Look at the super simple method!

题解 Pie(POJ3122)超详细易懂的二分入门

Leetcode 36. 有效的数独(可以,一次过)

API gateway Apache APIs IX helps the evolution of snowball dual active architecture
![[Note: circuit intégré MOS analogique] référence de bande Gap (principe de base + mode courant + circuit en mode tension)](/img/cd/be62272d465ca990456c222b38df67.png)
[Note: circuit intégré MOS analogique] référence de bande Gap (principe de base + mode courant + circuit en mode tension)
随机推荐
Leetcode daily question - 324 Swing sort II
openGauss内核分析之查询重写
Flask - Summary
The comprehensive application of the setstack computer (uva12096) Purple Book p116stl
接口用例设计
The further application of Li Kou tree
How to analyze the relationship between enterprise digital transformation and data asset management?
CNN-LSTM的flatten
Leetcode daily question - 710 Random numbers in the blacklist
嵌入式中 动态阿拉伯语字符串 转换 LCD显示字符串【感谢建国雄心】
穩定性總結
Leetcode 36. Effective Sudoku (yes, once)
input separator
Is it safe to open a dig money account? Is it reliable?
LeetCode1114. 按序打印
LeetCode每日一题——324. 摆动排序 II
GlobalSign的泛域名SSL证书
数据标准化处理
Mongodb - replica set and sharding
Automatic operation and maintenance platform based on Apache APIs