Description
Given an array of intervals, merge all overlapping intervals and return an array of the non-overlapping intervals.
Examples
Input:
intervals = [[1,3],[2,6],[8,10],[15,18]]Output:
[[1,6],[8,10],[15,18]]Explanation:
[1,3] and [2,6] overlap into [1,6].
Input:
intervals = [[2,5],[1,3],[7,9],[6,8]]Output:
[[1,5],[6,9]]Explanation:
After sorting by start time: [[1,3],[2,5],[6,8],[7,9]]. [1,3] and [2,5] overlap to form [1,5]. [6,8] and [7,9] overlap to form [6,9].
Input:
intervals = [[1,4],[2,3]]Output:
[[1,4]]Explanation:
The interval [2,3] is completely contained within [1,4], so they merge into the larger interval [1,4].
Constraints
- •
1 ≤ intervals.length ≤ 10⁴ - •
intervals[i].length == 2