@@ -0,0 +1,1144 @@
+// Given a collection of intervals, merge all overlapping intervals.%0A%0A// For example,%0A// Given %5B1,3%5D,%5B2,6%5D,%5B8,10%5D,%5B15,18%5D,%0A// return %5B1,6%5D,%5B8,10%5D,%5B15,18%5D.%0A%0A/**%0A * Definition for an interval.%0A * public class Interval %7B%0A *     int start;%0A *     int end;%0A *     Interval() %7B start = 0; end = 0; %7D%0A *     Interval(int s, int e) %7B start = s; end = e; %7D%0A * %7D%0A */%0Apublic class Solution %7B%0A    public List%3CInterval%3E merge(List%3CInterval%3E intervals) %7B%0A    %09if(intervals == null %7C%7C intervals.size() == 0) return intervals;%0A%0A    %09List%3CInterval%3E list = new ArrayList%3CInterval%3E();%0A%0A    %09Collections.sort(intervals, new Comparator%3CInterval%3E()%7B%0A    %09%09public int compare(Interval a, Interval b)%7B%0A    %09%09%09if(a.start %3E b.start) return 1;%0A    %09%09%09else if(a.start == b.start) return 0;%0A    %09%09%09else return -1;%0A    %09%09%7D%0A    %09%7D);%0A%0A    %09Interval last = intervals.get(0);%0A%0A    %09for(int i = 1; i %3C intervals.size(); i++)%7B%0A    %09%09Interval current = intervals.get(i);%0A    %09%09if(current.start %3C= last.end)%7B%0A    %09%09%09last.end = Math.max(last.end, current.end);%0A    %09%09%7Delse%7B%0A    %09%09%09list.add(last);%0A    %09%09%09last = current;%0A    %09%09%7D%0A    %09%7D%0A%0A    %09list.add(last);%0A%0A    %09return list;%0A    %7D%0A%7D

add merge intervals solution