Boats to Save People LeetCode solution in Python

1
class Solution:
2
def numRescueBoats(self, people: List[int], limit: int) -> int:
3
people.sort()
4
lo = 0
5
hi = len(people) - 1
6
boats = 0
7
while lo <= hi:
8
if people[lo] + people[hi] <= limit:
9
lo += 1
10
hi -= 1
11
else:
12
hi -= 1
13
boats += 1
14
return boats

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0