Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

Boats to Save People leetcode solution in c++

class Solution {
public:
    int numRescueBoats(vector<int>& people, int limit) {
        int n=people.size();
        sort(people.begin(),people.end());
        int cnt=0;
        int l=0, r=n-1;
        while(l<=r)
        {
            if(people[l]+people[r]<=limit)
                l++;
            r--;
            cnt++;
        }
        return cnt;
    }
};
Source by www.codegrepper.com #
 
PREVIOUS NEXT
Tagged: #Boats #Save #People #leetcode #solution
ADD COMMENT
Topic
Name
6+6 =