https://leetcode.com/problems/boats-to-save-people/description/
赤裸裸的双指针的题,,竟然没看出来。。。
class Solution {
public:
int numRescueBoats(vector<int>& people, int limit) {
sort(people.begin(), people.end());
int i = 0, j = people.size() - 1;
int ret = 0;
while (i <= j) {
// cout << "i:" << i << " j:" << j << endl;
if (people[j] + people[i] <= limit) {
i ++, j--;
} else {
j--;
}
ret ++;
}
return ret;
}
};