Skip to content

Commit 580d38a

Browse files
Create boats_to_save_people.cpp
1 parent 683fab4 commit 580d38a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

boats_to_save_people.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public:
3+
int numRescueBoats(vector<int>& people, int limit) {
4+
sort(people.begin(), people.end());
5+
int i = 0, j = people.size() - 1;
6+
int boats = 0;
7+
8+
while(i <= j){
9+
if(people[i] + people[j] <= limit)
10+
i++;
11+
j--;
12+
boats++;
13+
}
14+
return boats;
15+
}
16+
};

0 commit comments

Comments
 (0)