当前位置:网站首页>leetcode-57-插入区间
leetcode-57-插入区间
2022-06-10 13:17:00 【自己的九又四分之三站台】
1.问题描述
https://leetcode.cn/problems/insert-interval/
2. 解题代码
public class Solution {
public int[][] Insert(int[][] intervals, int[] newInterval) {
List<int[]> result = new List<int[]>();
int[] current = new int[2] { newInterval[0], newInterval[1]};
bool bAdd = true;
if (intervals.Length >0&& intervals[0][0]> current[1])
{
bAdd = false;
result.Add(current);
}
foreach (var item in intervals)
{
if (item[1] < current[0])
{
result.Add(item);
}
else if (item[0] > current[1])
{
if (bAdd)
{
bAdd = false;
result.Add(current);
}
result.Add(item);
}
else
{
current[0] = current[0] < item[0] ? current[0] : item[0];
current[1] = current[1] > item[1] ? current[1] : item[1];
}
}
if (bAdd)
{
result.Add(current);
}
return result.ToArray();
}
}
边栏推荐
- 【Golang】创建有配置参数的结构体时,可选参数应该怎么传?
- 移动app性能测试有哪些需要进行?性能测试报告如何收费?
- Leetcode 96. Différents arbres de recherche binaires
- Google Earth Engine(GEE)——基于s2影像的实时全球10米土地利用/土地覆盖(LULC)数据集
- mTabLayout. setOnTabSelectedListener is deprecated
- Neuron Newsletter 2022-05|新增 2 個南向驅動和 1 個北向應用、Modbus TCP 實現定制擴展
- 10、 Application of state machine model (cellular automata; gdb/rr/perf; code verification tool)
- WT2003H4-16S 语音芯片按键录音及播放应用解析
- client-go gin的简单整合六-list-watch二(关于Rs与Pod以及Deployment的完善)
- What is the p value of a gene?
猜你喜欢

2022 ciscn preliminary PWN complete WP

Final exam - Principles of compilation

Cvpr2022|aconvnetforthe2020s & how to design neural network Summary

win10虚拟机下载安装流程

汇编语言入门-总结

Introduction to assembly language - Summary
![[Netease Yunxin] in depth analysis of the design of](/img/48/e605357d0eced748c8f644f035052b.png)
[Netease Yunxin] in depth analysis of the design of "circle group" message system | series of articles on "circle group" technology
![buuctf [PHP]CVE-2019-11043](/img/ba/d97fe48acfd20daa66d47f34d99cf1.png)
buuctf [PHP]CVE-2019-11043

解决VMWareStation安装 tools 时 D:\setup.exe 找不到的问题

Application analysis of key recording and playing of wt2003h4-16s voice chip
随机推荐
Google Earth Engine(GEE)——基于s2影像的实时全球10米土地利用/土地覆盖(LULC)数据集
Some words from ShareIt group
How about the one-stop machine learning opening platform mlflow?
What needs to be done for mobile app performance testing? How much is the performance test report charged?
大四应届毕业生,想自学软件测试,如何应对面试?
Sohu employees encounter wage subsidy fraud. What is the difference between black property and gray property and how to trace the source?
出海企业遇瓶颈 茄子科技(SHAREit Group)有话说
QA of some high frequency problems in oauth2 learning
CVPR2022|AConvNetforthe2020s&如何设计神经网络总结
[FAQ] summary of common problems and solutions during the use of rest API interface of sports health service
谷歌提出超强预训练模型CoCa,在ImageNet上微调Top-1准确率达91%!在多个下游任务上SOTA!
Introduction to assembly language - Summary
NanoMQ Newsletter 2022-05|v0.8.0 发布,新增 WebHook 拓展接口和连接认证 API
What is the p value of a gene?
Ekuiper newsletter 2022-05 protobuf codec support, visual drag and drop writing rules
不吐不快
Some coding tips
Libre circulation des ressources dans le cloud et localement
"Reduce the burden" so that the "pig" can fly higher
How to write code that is not easy to overflow memory