Boats to Save People LeetCode solution in Java

1
class Solution {
2
public int numRescueBoats(int[] people, int limit) {
3
int boatCount = 0;
4
Arrays.sort(people);
5

6
int left = 0;
7
int right = people.length - 1;
8

9
while (left <= right) {
10
int sum = people[left] + people[right];
11
if (sum <= limit) {
12
boatCount++;
13
left++;
14
right--;
15
} else {
16
boatCount++;
17
right--;
18
}
19
}
20
return boatCount;
21
}
22
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0