Original URL:
http://www.jiuzhang.com/problem/78/
The problem details give a list of intervals that are not overlapping, sorted by interval start endpoint.
Insert a new interval in the list, and make sure that the intervals in the list are still orderly and not overlapping (you can merge the bands if necessary).
Online evaluation of the subject: http://www.lintcode.com/zh-cn/problem/insert-interval/
The answer to this question is mainly to examine the process of detail processing, because after the insertion of the interval may appear three possible. 1, inserted in the head, 2, inserted in the middle, 3, inserted at the end. 1th, 3 good processing, the direct judgment is in the head or in the tail, directly joins is good. Then the 2nd need to determine whether the interval after insertion can be combined with other intervals. So scan it again to see if there are any bands that can be merged, and then merge them together.
* Reference Code *http://www.jiuzhang.com/solutions/insert-interval/
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Nine-chapter algorithm surface question 77 Insert interval