当前位置:网站首页>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
边栏推荐
- Web自动化工具选择
- Leetcode daily question - 30 Concatenate substrings of all words
- 嵌入式中 动态阿拉伯语字符串 转换 LCD显示字符串【感谢建国雄心】
- 关于不完全类型的认识
- [graduation season · advanced technology Er] hard work can only pass, hard work can be excellent!
- LeetCode1114. 按序打印
- Leetcode daily question - 515 Find the maximum value in each tree row
- Visualization of neural network structure in different frames
- Automatic operation and maintenance platform based on Apache APIs
- Flatten of cnn-lstm
猜你喜欢

【学习笔记】主成分分析法介绍

方 差 分 析

Leetcode 36. Effective Sudoku (yes, once)

力扣树的进一步应用

Learn Tai Chi maker mqtt Chapter 2 (VIII) esp8266 mqtt user password authentication

How to use dataant to monitor Apache apisex

Ehcache配置资料,方便自己查

Figure neural network can also be used as CV backbone model. Huawei Noah Vig architecture is comparable to CNN and transformer
![[learning notes] Introduction to principal component analysis](/img/24/a760d1cd095a967ef258b623eb465c.png)
[learning notes] Introduction to principal component analysis

Analysis of variance
随机推荐
with torch. no_ Grad(): reason for using
数据标准化处理
LeetCode117. 填充每个节点的下一个右侧节点指针_II
Resilience4j retry source code analysis and retry index collection
Relevant calculation of sphere, etc
Ref attribute, props configuration, mixin mixing, plug-in, scoped style
LeetCode986. 区间列表的交集
Data standardization processing
[Note: circuit intégré MOS analogique] référence de bande Gap (principe de base + mode courant + circuit en mode tension)
Figure neural network can also be used as CV backbone model. Huawei Noah Vig architecture is comparable to CNN and transformer
Bitbucket failed to pull the warehouse Using SSH
题解 The Blocks Problem(UVa101)紫书P110vector的应用
Learn Tai Chi maker mqtt Chapter 2 (VIII) esp8266 mqtt user password authentication
Ehcache配置资料,方便自己查
如何使用 DataAnt 监控 Apache APISIX
Leetcode 36. 有效的数独(可以,一次过)
LeetCode213. 打家劫舍II
应用实践 | 10 亿数据秒级关联,货拉拉基于 Apache Doris 的 OLAP 体系演进(附 PPT 下载)
券商公司开户哪个最靠谱最安全呢
题解 The SetStack Computer(UVa12096)紫书P116STL的综合应用