DEV Community

Miss Pooja Anilkumar Patel
Miss Pooja Anilkumar Patel

Posted on

881. Leetcode Solution in cpp

class Solution { public: int numRescueBoats(vector<int>& people, int limit) { int ans = 0; sort(begin(people), end(people)); for (int i = 0, j = people.size() - 1; i <= j; ++ans) { int remain = limit - people[j--]; if (people[i] <= remain) ++i; } return ans; } }; 
Enter fullscreen mode Exit fullscreen mode

leetcode

challenge

Here is the link for the problem:
https://leetcode.com/problems/boats-to-save-people/

Top comments (0)