-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path436.cpp
More file actions
executable file
·24 lines (24 loc) · 760 Bytes
/
436.cpp
File metadata and controls
executable file
·24 lines (24 loc) · 760 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution {
public:
vector<int> findRightInterval(vector<vector<int>>& intervals) {
unordered_map<int,int> start2index;
vector<int> starts;
int index = 0;
for (auto interval : intervals) {
starts.push_back(interval[0]);
start2index[interval[0]] = index;
index++;
}
sort(starts.begin(), starts.end());
vector<int> res;
for (auto interval : intervals) {
vector<int>::iterator low = lower_bound(starts.begin(), starts.end(), interval[1]);
if (starts.back() < interval[1]){
res.push_back(-1);
}else{
res.push_back(start2index[*low]);
}
}
return res;
}
};