解题思路:
相当简单的中等题,主要在于题目的理解,其实就是在数组中寻找比每一项的end大、最小的start所在区间的下标,用map存储区间的下标,用二分法查找是否存在该start,返回下标或者-1,代码如下:
class Solution {
public:
vector findRightInterval(vector>& intervals) {
map mp;
vector res;
for(int i = 0; i < intervals.size(); i ++) {
mp[intervals[i][0]] = i;
}
for(auto& interval : intervals) {
auto it = mp.lower_bound(interval[1]);
int index;
if(it != mp.end()) {
index = it->second;
} else index = -1;
res.push_back(index);
}
return res;
}
};


![LeetCode 436 寻找右区间[map 二分法] HERODING的LeetCode之路 LeetCode 436 寻找右区间[map 二分法] HERODING的LeetCode之路](http://www.mshxw.com/aiimages/31/916836.png)
