Skip to content

Commit

Permalink
Create 13.cc
Browse files Browse the repository at this point in the history
  • Loading branch information
pin3da authored Jan 13, 2021
1 parent 01362b0 commit fd7e4cb
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions solved/LeetCode/Challenges/2020/January/13.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution {
public:
int numRescueBoats(vector<int>& people, int limit) {
sort(people.begin(), people.end());
deque<int> q;
for (auto it : people) q.push_back(it);

int boats = 0;

while (q.size() > 1) {
boats++;
int last = q.back();
q.pop_back();
if (last + q.front() <= limit) {
q.pop_front();
}
}

return boats + q.size();
}
};

0 comments on commit fd7e4cb

Please sign in to comment.