Tuesday, October 14, 2014

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

Idea

先把interval按照start排序,把第一个压入结果result中,遍历后面的如果发现conflict则更新result.back的end,若没有conflict则继续压。

Solution


No comments:

Post a Comment