| 문제
Given a collection of intervals, merge all overlapping intervals.
Example 1:
Input: intervals = [[1,3],[2,6],[8,10],[15,18]]
Output: [[1,6],[8,10],[15,18]]
Explanation: Since intervals [1,3] and [2,6] overlaps, merge them into [1,6].
Example 2
Input: intervals = [[1,4],[4,5]]
Output: [[1,5]]
Explanation: Intervals [1,4] and [4,5] are considered overlapping.
⏰ Runtime: 84 ms, faster than 85.43% of JavaScript online submissions for Merge Intervals.
풀이 요약
- 빈 배열 투입할 경우 그대로 리턴하도록 처리
- intervals 배열 오름차순 정렬하여 준비
- 반복문으로 <인터벌 겹칠때/겹치지 않을 때>를 나누어 배열을 result에 push