class Solution {
public:
int numRescueBoats(vector
<int>& people
, int limit
) {
sort(people
.begin(), people
.end());
int lo
= 0, hi
= people
.size()-1;
int res
= 0;
while(lo
< hi
){
if((people
[lo
] + people
[hi
]) <= limit
){
res
++;
lo
++;
hi
--;
}
else{
hi
--;
res
++;
}
}
if(lo
== hi
)
res
++;
return res
;
}
};
转载请注明原文地址:https://tech.qufami.com/read-6456.html