← 返回 bytedance 的题目列表Merge Intervals
类型:online_judge
Merge Intervals
Given n closed intervals intervals, where intervals[i] = [start_i, end_i], merge all overlapping intervals and return a list of non-overlapping intervals that covers all input intervals.
Two closed intervals that touch at an endpoint, such as [1, 4] and [4, 5], must also be merged into [1, 5].
Input Format
First line: an integer n, the number of intervals.
Next n lines: two integers start end, representing a closed interval [start, end].
Output Format
Print the merged intervals, one interval per line, in the format start end.
Constraints
1 <= n <= 10^5
0 <= start_i <= end_i <= 10^9
Example 1
Input:
4
1 3
2 6
8 10
15 18
Output:
1 6
8 10
15 18
Example 2
Input:
2
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