We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6e1801d commit 33716c7Copy full SHA for 33716c7
java/0881-boats-to-save-people.java
@@ -0,0 +1,15 @@
1
+class Solution {
2
+ public int numRescueBoats(int[] people, int limit) {
3
+ Arrays.sort(people);
4
+ int boatsNeeded = 0;
5
+ int lightIdx = 0;
6
+ int heavyIdx = people.length-1;
7
+ while (lightIdx <= heavyIdx) {
8
+ if (people[lightIdx] + people[heavyIdx] <= limit)
9
+ lightIdx++;
10
+ heavyIdx--;
11
+ boatsNeeded++;
12
+ }
13
+ return boatsNeeded;
14
15
+}
0 commit comments