Nine-chapter algorithm surface question 77 Insert interval

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.