leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0881.cpp (353B)


      1 class Solution {
      2   public:
      3     int numRescueBoats(vector<int> &people, int limit) {
      4         sort(people.begin(), people.end());
      5         int low = 0, high = people.size() - 1, res = 0;
      6         while (low <= high) {
      7             if (people[low] + people[high] <= limit) low++;
      8             high--;
      9             res++;
     10         }
     11 
     12         return res;
     13     }
     14 };