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].
The Idea: We can sort the intervals by start time, the intervals would fall under one of three cases which are illustrated below. In the first case, there are no updates. In the second case, the interval end updates, and in the third case, we add the previous interval and update the current interval.