使用最简单的排序方法;
1 /** 2 * Definition for an interval. 3 * public class Interval { 4 * int start; 5 * int end; 6 * Interval() { start = 0; end = 0; } 7 * Interval(int s, int e) { start = s; end = e; } 8 * } 9 */10 public class Solution {11 public Listmerge(List intervals) {12 if(intervals.size()<=1) return intervals;13 ArrayList arry=new ArrayList ();14 Comparator cmp=new Comparator (){15 public int compare(Interval v1,Interval v2)16 {17 return v1.start-v2.start;18 }19 20 21 22 };23 Collections.sort(intervals,cmp);24 Interval pre=intervals.get(0);25 for(int i=1;i