1. Brief Introduction
Given a source interval [x, y] (Y> = x) and N unordered target intervals [X1, Y1] [X2, y2] [X3, Y3]... [XN] [YN]: determines whether [x, y] is within the target range.
2. Ideas
This is relatively simple. Merge the target interval and determine whether the source interval is within the target interval. The specific process is as follows:
Step 1: first sort the target intervals.
Step 2: starting from the first interval, traverse first to find a [XI, Yi] So that xi <= x. If it cannot be found, it means it is not in the target interval, if Yi> = y is found, the work is finished. The source interval is within the target interval. If Yi <Y is found, traverse the source interval to step 3.
Step 3, continue traversing [XI, Yi], if xi> Y (I-1), then the interval is broken, the source interval is not within the target interval, otherwise if Yi> = Y, found, the source range is within the target range; otherwise, the search continues.
Step 4: If the traversal ends, but the source interval is not found to be within the target interval, it means that the source interval is not within the target interval.
Step 1: N * logn, step 2 + step 3, step N, step 4, and step 1. Complexity: O (n logn)
3. Reference
Programming beauty, 2.19, interval coincidence judgment