leetcode56:Merge Intervals
大都是自定义了 Interval的比较方法。
突发奇想
int [] arr=new int[intervals.Count*2];
for(int i=0;i<intervals.Count;i++)
{
arr[i*2]=intervals[i].start*10+1;
arr[i*2+1]=intervals[i].end*10+2;
}
Array.Sort(arr);
IList<Interval> list=new List<Interval>(); int s=0;//int e=1;
int count=0;
for(int i=0;i<arr.Length;i++)
{
if(arr[i]%2==1) count++;
else if(arr[i]%2==0) count--;
if(count==0)
{
list.Add(new Interval(arr[s]/10,arr[i]/10));
s=i+1;
}
}
return list;
leetcode56:Merge Intervals的更多相关文章
- LeetCode OJ:Merge Intervals(合并区间)
Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8, ...
- LeetCode第[56]题(Java):Merge Intervals
题目:合并区间 难度:Medium 题目内容: Given a collection of intervals, merge all overlapping intervals. 翻译: 给定一个 ...
- [array] leetcode-56. Merge Intervals - Medium
leetcode-56. Merge Intervals - Medium descrition Given a collection of intervals, merge all overlapp ...
- [LeetCode] Merge Interval系列,题:Insert Interval,Merge Intervals
Interval的合并时比较常见的一类题目,网上的Amazon面经上也有面试这道题的记录.这里以LeetCode上的例题做练习. Merge Intervals Given a collection ...
- 【leetcode】Merge Intervals(hard)
Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...
- 60. Insert Interval && Merge Intervals
Insert Interval Given a set of non-overlapping intervals, insert a new interval into the intervals ( ...
- 【题解】【区间】【二分查找】【Leetcode】Insert Interval & Merge Intervals
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessa ...
- 【leetcode】 Merge Intervals
Merge Intervals Given a collection of intervals, merge all overlapping intervals. For example,Given ...
- Insert Interval & Merge Intervals
Insert Intervals Given a non-overlapping interval list which is sorted by start point. Insert a new ...
随机推荐
- CSS元素(文本、图片)水平垂直居中方法
1.text-align:center; 2.margin:0 auto; 3.display:inline-block; + text-align:center; 4.position:relati ...
- ASP.NET MVC WebAPI 资源整理
注:这是收集给公司同事学习的资料,入门级别的. 使用ASP.Net WebAPI构建REST服务(一)——简单的示例 http://blog.csdn.net/mengzhengjie/article ...
- Linux 学习笔记之超详细基础linux命令 Part 12
Linux学习笔记之超详细基础linux命令 by:授客 QQ:1033553122 ---------------------------------接Part 11---------------- ...
- Linux 学习笔记之超详细基础linux命令 Part 8
Linux学习笔记之超详细基础linux命令 by:授客 QQ:1033553122 ---------------------------------接Part 7----------------- ...
- 创建Android Apps的30个经验教训
这个世界上有两种人-从经验教训中学习的人以及听从别人建议的人.这里是我一路走来学到的一些东西,分享给大家: 在添加任何第三方party之前,请三思:这真的是一个成熟的项目吗? 如果一个东西用户看不到, ...
- (网页)JS和CSS不缓存方法,时间戳
<link ..... href=".....css?time"+new Date()> <script type="text/javascript&q ...
- 【redis专题(4)】命令语法介绍之sorted_set
有序集合可以模拟优先级队列的实现 增 zadd key score1 value1 score2 value2 .. redis 127.0.0.1:6379> zadd stu 18 lily ...
- [20171206]rman与truncate2.txt
[20171206]rman与truncate2.txt --//上午测试发现truncate的表在做rman备份时还要做8个extents的备份.--//不知道自己的猜测是否正确,选择一个使用UNI ...
- 第四章 Hyper-V 2012 R2 网络配置
尼玛的我不高兴写了,所以下面的文档我直接把原来的pdf给转换出来,加了点自己的注解,我写的话会写自己觉得终于的章节. 在搭建虚拟化平台时,网络的虚拟化是一个非常重要的环节,如何保障网络的持续可用并 ...
- Linux : Vim 使用与配置 (附 GitHub 自动化配置脚本)
由于经常使用 vim 编辑配置文件,有时候也会进行使用vim 编写一些脚本和c/c++ 程序,所以配置一个常用的 vim 是很是必要的.这篇博文主要是记录vim使用和配置相关的一些知识点. 关于vim ...