### 题目

Given a collection of intervals, merge all overlapping intervals.

For example,

Given [1,3],[2,6],[8,10],[15,18],
return [1,6],[8,10],[15,18].


### 先排序 $O(n\log_{}{n})$

#### 代码

public class Solution {
public List<Interval> merge(List<Interval> intervals) {
List<Interval> res = new ArrayList<>();
if (intervals.isEmpty()) { return res; }
Collections.sort(intervals, new Comparator<Interval>() {
public int compare(Interval first, Interval second) {
return first.start - second.start;
}
});
Interval pool = intervals.get(0);
for (Interval next : intervals) {
if (next.start > pool.end) {
pool = next;
} else {
pool.end = Math.max(pool.end,next.end);
}
}
return res;
}
private static class Interval {
int start;
int end;
Interval() { start = 0; end = 0; }
Interval(int s, int e) { start = s; end = e; }
}
}


#### Lambda Expression 简化版

A functional interface is any interface that contains only one abstract method.

public List<Interval> merge(List<Interval> intervals) {
List<Interval> res = new ArrayList<>();
if (intervals.isEmpty()) { return res; }
Collections.sort(intervals, (Interval first, Interval second) -> first.start - second.start);
Interval pool = intervals.get(0);
for (Interval next : intervals) {
if (next.start > pool.end) {