当前位置:网站首页>不会就坚持69天吧 合并区间
不会就坚持69天吧 合并区间
2022-07-29 04:13:00 【一只小小明】

class Solution {
public int[][] merge(int[][] intervals) {
if (intervals.length == 0) {
return new int[0][2];
}
Arrays.sort(intervals, new Comparator<int[]>() {
public int compare(int[] interval1, int[] interval2) {
return interval1[0] - interval2[0];
}
});
List<int[]> merged = new ArrayList<int[]>();
for (int i = 0; i < intervals.length; ++i) {
int L = intervals[i][0], R = intervals[i][1];
if (merged.size() == 0 || merged.get(merged.size() - 1)[1] < L) {
merged.add(new int[]{L, R});
} else {
merged.get(merged.size() - 1)[1] = Math.max(merged.get(merged.size() - 1)[1], R);
}
}
return merged.toArray(new int[merged.size()][]);
}
}
作者:LeetCode-Solution
链接:https://leetcode.cn/problems/SsGoHC/solution/he-bing-qu-jian-by-leetcode-solution-ghjl/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。边栏推荐
- pat A1041 Be Unique
- 为什么opengauss启动的时候这么多的unknown?
- Three tier architecture of enterprise network
- openFeign异步调用问题
- %s. %c, character constant, string constant, const char*, pointer array, string array summary
- [kvm] common commands
- [deep learning CPU (part outside) - virtual memory]
- Asp.net MVC中文件夹中的控制器如何跳转到根目录的控制器中?
- Solution: module 'xlrd' has no attribute 'open_ Error reporting of workbook '
- Is the browser multi process or single process?
猜你喜欢
![[paper translation] vectornet: encoding HD maps and agent dynamics from vectorized representation](/img/4b/150689d5e4809ae66a4297915ecd0c.png)
[paper translation] vectornet: encoding HD maps and agent dynamics from vectorized representation
![[Openstack] keystone,nova](/img/de/70b654a29a813c8fe828c4018bd4e7.png)
[Openstack] keystone,nova

Locally call tensorboard and Jupiter notebook on the server (using mobaxterm)

MPU6050

SQL window function

店铺排名问题,如何解决?

HCIP BGP

数据挖掘——关联分析基础介绍(上)

力扣面试题17.04 消失的数字||260.只出现一次的数字(内含位运算知识点)

MySQL gets the maximum value record by field grouping
随机推荐
A little understanding of pointer, secondary pointer, wild pointer, pointer as function return value
[kvm] common commands
pat A1041 Be Unique
Why are there so many unknowns when opengauss starts?
"Weilai Cup" 2022 Niuke summer multi school training camp 1 J serval and essay (heuristic merger)
Database SQL statement realizes function query of data decomposition
C语言实现三子棋游戏(详解)
C declaration and initialization and assignment
通过js来实现一元二次方程的效果,输入a,b,c系数后可计算出x1和x2的值
The output comparison function of Tim is introduced in detail through PWM breathing lamp and PWM controlled DC motor
(.*?) regular expression
Is the array name a pointer
通过PWM呼吸灯和PWM控制直流电机来详细介绍TIM的输出比较功能
Opensql quick learning
[untitled]
The table of antd hides the pager when there is only one page
编译与链接
BGP的基础配置---建立对等体、路由宣告
请问为什么我进行mysql数据update时,kafka中采集到的是先删除原纪录(op d)再新增新
安装postgis时报找不到“POSTGIS_VERSION”这个函数