Skip to content

Commit dfd1582

Browse files
authoredApr 3, 2023
Create 0881-boats-to-save-people.kt
1 parent 5c4da58 commit dfd1582

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
 

‎kotlin/0881-boats-to-save-people.kt

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
fun numRescueBoats(people: IntArray, limit: Int): Int {
3+
people.sort()
4+
5+
var left = 0
6+
var right = people.lastIndex
7+
var res = 0
8+
9+
while (left <= right) {
10+
if (people[left] + people[right] <= limit)
11+
left++
12+
right--
13+
res++
14+
}
15+
16+
return res
17+
}
18+
}

0 commit comments

Comments
 (0)
Please sign in to comment.