Greedy Problems - III
56. Merge Intervals
Similar to other sgement related problems. The first thing we need to do is to sort the slice. Once we have a sorted segment slice, we can iterate over all items and merge them. Note there is one edge case we need to cover after the iteration, either we merged all segments into one or the last one can’t be merged into the previous segment.
1 | func merge(intervals [][]int) [][]int { |