描述
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].
分析
和[Insert Interval][1]很像,解法也很类似,先按start排序然后遍历数组前后合并。
代码
Python
1 |
class (object): |
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].
和[Insert Interval][1]很像,解法也很类似,先按start排序然后遍历数组前后合并。
1 |
class (object): |
近期评论