LeetCode – Merge Intervals

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]. Analysis The key to solve this problem is defining a Comparator first to sort the arraylist of Intevals. Java Solution public List<Interval> merge(List<Interval> intervals) { if(intervals == null || intervals.size()<=1){ return intervals; }   Collections.sort(intervals, Comparator.comparing((Interval itl)->itl.start));   List<Interval> result … Read more