Skip to content

Commit 33716c7

Browse files
committed
Create 0881-boats-to-save-people.java
- File Modified: 0881-boats-to-save-people.java - Language Used: java - Submission URL: https://leetcode.com/problems/boats-to-save-people/submissions/975929350/
1 parent 6e1801d commit 33716c7

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)