typedef pair<int, int> PII;
class Solution {
public:
vector<PII> hash;
int find(int x)
{
int l = 0, r = hash.size() - 1;
while(l < r)
{
int mid = (l + r) >> 1;
if(hash[mid].first >= x) r = mid;
else l = mid + 1;
}
if(hash[r].first >= x)
return hash[r].second;
else
return -1;
}
vector<int> findRightInterval(vector<vector<int>>& intervals) {
int n = intervals.size();
for(int i = 0; i < n; i ++)
{
hash.push_back({intervals[i][0], i});
}
sort(hash.begin(), hash.end());
vector<int> res();
for(int i = 0; i < n; i ++)
{
int t = find(intervals[i][1]);
res.push_back(t);
}
return res;
}
};
LeetCode 436. 寻找右区间
于 2022-05-20 12:22:03 首次发布