class Solution {
public:
int numRescueBoats(vector<int>& people, int limit) {
sort(people.begin(),people.end());
int l=0;int r=people.size()-1;
int ans = 0;
while(l<=r){
int ll = people[l];
int rr = people[r];
if(ll+rr<=limit){
l++;r--;ans++;
continue;
}
if(ll+rr>limit){
r--;ans++;
}
}
return ans;
}
};
댓글 0