大都是自定义了 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的更多相关文章

  1. LeetCode OJ:Merge Intervals(合并区间)

    Given a collection of intervals, merge all overlapping intervals. For example,Given  [1,3],[2,6],[8, ...

  2. LeetCode第[56]题(Java):Merge Intervals

    题目:合并区间 难度:Medium 题目内容:   Given a collection of intervals, merge all overlapping intervals. 翻译: 给定一个 ...

  3. [array] leetcode-56. Merge Intervals - Medium

    leetcode-56. Merge Intervals - Medium descrition Given a collection of intervals, merge all overlapp ...

  4. [LeetCode] Merge Interval系列,题:Insert Interval,Merge Intervals

    Interval的合并时比较常见的一类题目,网上的Amazon面经上也有面试这道题的记录.这里以LeetCode上的例题做练习. Merge Intervals Given a collection ...

  5. 【leetcode】Merge Intervals(hard)

    Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...

  6. 60. Insert Interval && Merge Intervals

    Insert Interval Given a set of non-overlapping intervals, insert a new interval into the intervals ( ...

  7. 【题解】【区间】【二分查找】【Leetcode】Insert Interval & Merge Intervals

    Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessa ...

  8. 【leetcode】 Merge Intervals

    Merge Intervals Given a collection of intervals, merge all overlapping intervals. For example,Given  ...

  9. Insert Interval & Merge Intervals

    Insert Intervals Given a non-overlapping interval list which is sorted by start point. Insert a new ...

随机推荐

  1. java获取文件路径

    情况:工程项目没有放到tomcat下,在eclipse运行 1.获取项目根目录,根据在哪里运行 2. 3.从最终生成的.class文件为着手点 4.在controller下

  2. Android Color颜色代码

    常用颜色代码 <?xml version="1.0" encoding="utf-8"?> <resources> <color ...

  3. LyX快捷键管理

    快捷键修改:Tools->Preference->Editing->Shortcuts:修改后要Tools->Reconfig生效 快捷键默认保存文件:%appdata%\Ly ...

  4. Expect 安装 on centos7

    本文演示如何在CentOS7上安装和使用Expect. 使用场景 在主机A上编写并且执行Shell脚本,Shell脚本中需要ssh到主机B上执行交互命令. 安装 在主机A上安装expect: yum ...

  5. jquery常用表单操作

    //js将表单序列化成对象 $.fn.serializeObject = function () { var $els = $(this).find("[name]"); var ...

  6. Nginx 错误日志配置

    1.Nginx错误日志信息介绍: error_log的语法格式及参数说明: error_log      file         level; 关键字    日志文件   错误日志级别 其中,关键字 ...

  7. Android 发送自定义广播(标准和本地)

    1.首先自定义一个广播接收器:MyBroadcastReceiver package example.com.mybroadcastreceiver; import android.content.B ...

  8. Kubernetes 核心概念

    什么是Kubernetes? Kubernetes(k8s)是自动化容器操作的开源平台,这些操作包括部署,调度和节点集群间扩展.如果你曾经用过Docker容器技术部署容器,那么可以将Docker看成K ...

  9. shell基本语法记录

    Shell 是一个用 C 语言编写的程序,它是用户使用 Linux 的桥梁.Shell 既是一种命令语言,又是一种程序设计语言. Shell 是指一种应用程序,这个应用程序提供了一个界面,用户通过这个 ...

  10. Nginx禁止目录执行php文件权限

    location ~ /dir/.*.(php|php5)?$ { deny all; } 禁止dir目录执行php文件权限 .csharpcode, .csharpcode pre { font-s ...