Skip to content

Commit 29412be

Browse files
Create _881.java
1 parent 9a9db67 commit 29412be

File tree

1 file changed

+26
-0
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _881 {
4+
public static class Solution1 {
5+
public int numRescueBoats(int[] people, int limit) {
6+
Arrays.sort(people);
7+
int end = people.length - 1;
8+
int start = 0;
9+
int boatcount = 0;
10+
while (end >= start) {
11+
if (people[end] == limit) {
12+
end--;
13+
boatcount++;
14+
} else if (people[end] + people[start] <= limit) {
15+
start++;
16+
end--;
17+
boatcount++;
18+
} else {
19+
end--;
20+
boatcount++;
21+
}
22+
}
23+
return boatcount;
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)