[Java][LeetCode][Intervals] Meger Intervals #56
Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals and return an array of the non-overlapping intervals that cover all the intervals in the input.
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].

Sort方式: Arrays.sort(intervals,(a,b)->a[0]-b[0])
Sort “start” 由小到大,檢查迴圈當前的start是否小於或等於指標值(point,前一個的end),有的話則數組為連續,為了合併連續的數組,所以需要紀錄連續數組的最小值與最大值。在不連續的時候,便將數組輸出存到List中,如果前面的數組是連續的,就用最小值與最大值產生一個數組放到List中; 如果前面數組是不連續的,那就把前面數組放到List中,直到回圈跑完。迴圈結束之後,還需要將最後一組數組放到List中。
Sort [start] from less to greater. Check dose the start of the current array is equal to or less than the end of the last array. To combine intervals when the intervals are continuity, I keep the min from the start element of the first interval and the max from the end element of the current interval. When the interval didn’t continue with the ahead of the interval, I will fill out the new interval(array) to List. If ahead of intervals were continuous, I fill out the min and max to the new interval, else fill out the ahead of the interval to List. Until the for-loop finish, I still have the last interval need to fill out to List (because I fill out interval to List is when current interval with ahead interval didn’t continuous).