11[#0436-find-right-interval]
2- = 436. Find Right Interval
2+ = 436. 寻找右区间
33
4- { leetcode} /problems/find-right-interval/[LeetCode - Find Right Interval ^]
4+ https:// leetcode.cn /problems/find-right-interval/[LeetCode - 436. 寻找右区间 ^]
55
6- Given a set of intervals, for each of the interval i, check if there exists an interval j whose start point is bigger than or equal to the end point of the interval i, which can be called that j is on the "right" of i.
6+ 给你一个区间数组 `intervals` ,其中 ` intervals[i] = [start~i~, end~i~]` ,且每个 `start~i~` 都 *不同* 。
77
8- For any interval i, you need to store the minimum interval j's index, which means that the interval j has the minimum start point to build the "right" relationship for interval i. If the interval j doesn't exist, store -1 for the interval i. Finally, you need output the stored value of each interval as an array.
8+ 区间 `i` 的 *右侧区间* 可以记作区间 `j` ,并满足 `start~j~ >= end~i~` ,且 ` start~j~` *最小化* 。注意 `i` 可能等于 `j` 。
99
10- *Note:*
10+ 返回一个由每个区间 `i` 的 *右侧区间* 在 `intervals` 中对应下标组成的数组。如果某个区间 `i` 不存在对应的 *右侧区间* ,则下标 `i` 处的值设为 `-1` 。
1111
12+ *示例 1:*
1213
13- . You may assume the interval's end point is always bigger than its start point.
14- . You may assume none of these intervals have the same start point.
14+ ....
15+ 输入:intervals = [[1,2]]
16+ 输出:[-1]
17+ 解释:集合中只有一个区间,所以输出-1。
18+ ....
1519
20+ *示例 2:*
1621
17-
22+ ....
23+ 输入:intervals = [[3,4],[2,3],[1,2]]
24+ 输出:[-1,0,1]
25+ 解释:对于 [3,4] ,没有满足条件的“右侧”区间。
26+ 对于 [2,3] ,区间[3,4]具有最小的“右”起点;
27+ 对于 [1,2] ,区间[2,3]具有最小的“右”起点。
28+ ....
1829
19- *Example 1: *
30+ *示例 3: *
2031
21- [subs="verbatim,quotes,macros"]
22- ----
23- *Input:* [ [1,2] ]
24-
25- *Output:* [-1]
26-
27- *Explanation:* There is only one interval in the collection, so it outputs -1.
28- ----
29-
30-
32+ ....
33+ 输入:intervals = [[1,4],[2,3],[3,4]]
34+ 输出:[-1,2,-1]
35+ 解释:对于区间 [1,4] 和 [3,4] ,没有满足条件的“右侧”区间。
36+ 对于 [2,3] ,区间 [3,4] 有最小的“右”起点。
37+ ....
3138
32- *Example 2:*
33-
34- [subs="verbatim,quotes,macros"]
35- ----
36- *Input:* [ [3,4], [2,3], [1,2] ]
37-
38- *Output:* [-1, 0, 1]
39-
40- *Explanation:* There is no satisfied "right" interval for [3,4].
41- For [2,3], the interval [3,4] has minimum-"right" start point;
42- For [1,2], the interval [2,3] has minimum-"right" start point.
43- ----
39+ *提示:*
4440
45-
41+ * `1 \<= intervals.length \<= 2 * 10^4^`
42+ * `+intervals[i].length == 2+`
43+ * `-10^6^ \<= start~i~ \<= end~i~ \<= 10^6^`
44+ * 每个间隔的起点都 *不相同*
4645
47- *Example 3:*
48-
49- [subs="verbatim,quotes,macros"]
50- ----
51- *Input:* [ [1,4], [2,3], [3,4] ]
52-
53- *Output:* [-1, 2, -1]
54-
55- *Explanation:* There is no satisfied "right" interval for [1,4] and [3,4].
56- For [2,3], the interval [3,4] has minimum-"right" start point.
57- ----
58-
59- *NOTE:* input types have been changed on April 15, 2019. Please reset to default code definition to get new method signature.
6046
6147== 思路分析
6248
49+ 排序+二分查找。由于左端点都不同,可以根据左端点的值来来对区间进行排序。然后在这个有序序列中,查找右端点的“最近左端点”。
50+
6351[[src-0436]]
6452[tabs]
6553====
@@ -77,8 +65,14 @@ include::{sourcedir}/_0436_FindRightInterval.java[tag=answer]
7765// --
7866// [{java_src_attr}]
7967// ----
80- // include::{sourcedir}/_0005_LongestPalindromicSubstring_2 .java[tag=answer]
68+ // include::{sourcedir}/_0436_FindRightInterval_2 .java[tag=answer]
8169// ----
8270// --
8371====
8472
73+
74+ == 参考资料
75+
76+ . https://leetcode.cn/problems/find-right-interval/solutions/1506129/by-ac_oier-sijp/[436. 寻找右区间 - 一题双解 :「排序 + 二分」&「双指针(莫队思想)」^]
77+ . https://leetcode.cn/problems/find-right-interval/solutions/1504095/xun-zhao-you-qu-jian-by-leetcode-solutio-w2ic/[436. 寻找右区间 - 官方题解^]
78+ . https://leetcode.cn/problems/find-right-interval/solutions/52077/er-fen-cha-zhao-hong-hei-shu-by-liweiwei1419/[436. 寻找右区间 - 二分查找、二分搜索树^]
0 commit comments