We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
参考秀哥代码时,这个例子会出问题:输入intervals =[[4,4]] 输出[-1] 预期结果[0] 添加一个if判断看是否会出现只有一个子数组内两个元素相等情况,有就返回{0},成功通过 vector findRightInterval(vector<vector>& intervals) { int len=intervals.size(); if(len<=1){ if(intervals[0][1]==intervals[0][0]){ return {0}; } else{ return {-1}; } } map<int,int> m; vector res; res.reserve(len); for(int i=0;i<len;i++){ m[intervals[i][0]]=i; } for(auto& a:intervals){ auto it=m.lower_bound(a[1]); if(it!=m.end()){ res.push_back(it->second); } else{ res.push_back(-1); } } return res; }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
参考秀哥代码时,这个例子会出问题:输入intervals =[[4,4]] 输出[-1] 预期结果[0]
添加一个if判断看是否会出现只有一个子数组内两个元素相等情况,有就返回{0},成功通过
vector findRightInterval(vector<vector>& intervals) {
int len=intervals.size();
if(len<=1){
if(intervals[0][1]==intervals[0][0]){
return {0};
}
else{
return {-1};
}
}
map<int,int> m;
vector res;
res.reserve(len);
for(int i=0;i<len;i++){
m[intervals[i][0]]=i;
}
for(auto& a:intervals){
auto it=m.lower_bound(a[1]);
if(it!=m.end()){
res.push_back(it->second);
}
else{
res.push_back(-1);
}
}
return res;
}
The text was updated successfully, but these errors were encountered: