Merge Intervals Archives - Coddicted

Merge Intervals

Title: Merge Intervals Source: leetcode.com 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]. Java solution Java /* https://leetcode.com/problems/merge-intervals/ */ import java.util.List; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Stack; public class MergeIntervals { public List<Interval> merge(List<Interval> intervals) { this.sort(intervals); Stack<Interval> stack = new Stack<>(); for(Interval interval : intervals) ...