Last active
January 13, 2021 13:26
-
-
Save Desolve/c315324b270acabd8a584d6b8554adf8 to your computer and use it in GitHub Desktop.
0881 Boats to Save People
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def numRescueBoats(self, people: List[int], limit: int) -> int: | |
people.sort() | |
l, r = 0, len(people) - 1 | |
res = 0 | |
while l <= r: | |
if people[l] + people[r] <= limit: l += 1 | |
r -= 1 | |
res += 1 | |
return res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment