← 返回 rippling 的题目列表Merge Overlapping Intervals
类型:online_judge
Given a list of intervals intervals where intervals[i] = [start_i, end_i] and start_i <= end_i, merge all overlapping intervals and return the merged list.
Two intervals [a,b] and [c,d] overlap if c <= b (assuming intervals are processed in increasing start order), and can be merged into [a, max(b,d)].
Requirements:
Return intervals sorted by start.
Aim for O(n log n) time due to sorting.
Constraints:
1 <= n <= 2e5
-1e9 <= start_i, end_i <= 1e9
Examples:
Input: [[1,3],[2,6],[8,10],[15,18]] Output: [[1,6],[8,10],[15,18]]
Input: [[1,4],[4,5]] Output: [[1,5]]
Example
Input
4
1 3
2 6
8 10
15 18
Output
1 6
8 10
15 18