diff --git a/solved/LeetCode/Challenges/2020/January/13.cc b/solved/LeetCode/Challenges/2020/January/13.cc new file mode 100644 index 00000000..e7a7d951 --- /dev/null +++ b/solved/LeetCode/Challenges/2020/January/13.cc @@ -0,0 +1,21 @@ +class Solution { +public: + int numRescueBoats(vector& people, int limit) { + sort(people.begin(), people.end()); + deque 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(); + } +};