Wednesday, July 9, 2014

[Leetcode] Merge Intervals

Problem

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].

Algorithm 

Each interval has a start time and an end time. Sort these intervals by their starting time. Add non overlapping intervals into the result list, and merge the overlapping intervals.
Remember how to write a Comparator class.

Code


No comments:

Post a Comment