来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/find-right-interval
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
| 题目大意是这样的 |
| 数组中的元素由一个区间组成(包含一个左端点和右端点),左端点一定是唯一的 |
| 找到每个元素的右区间 |
| 举个例子 |
| 假设区间A为[1,2],那么区间A的右区间最好就是[2,3] |
| 也就是说区间A右区间的左端点是大于等于区间A右端点的最小数 |
代码如下
| class Solution { |
| public: |
| vector<int> findRightInterval(vector<vector<int>>& intervals) { |
| vector<int> res; |
| |
| |
| if(intervals.size()==1){ |
| res.push_back(-1); |
| return res; |
| } |
| |
| int a,b; |
| for(int i=0;i |
| int j=0; |
| |
| b = 1e6+10; |
| for(;j |
| if(intervals[j][0]>=intervals[i][1] && intervals[j][0] |
| b = intervals[j][0]; |
| a=j; |
| } |
| } |
| if(b!=1e6+10)res.push_back(a); |
| else res.push_back(-1); |
| } |
| |
| return res; |
| } |
| }; |