Skip to content

Commit 2f87c92

Browse files
committed
May 4
1 parent e5b2258 commit 2f87c92

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def numRescueBoats(self, people: List[int], limit: int) -> int:
6+
people.sort()
7+
left, right = 0, len(people)-1
8+
boats = 0
9+
while left <= right:
10+
person = people[right]
11+
if person + people[left] <= limit:
12+
left += 1
13+
right -= 1
14+
boats += 1
15+
return boats
16+
17+
18+
def main():
19+
people = [1, 2]
20+
limit = 3
21+
assert Solution().numRescueBoats(people, limit) == 1
22+
23+
people = [3, 2, 2, 1]
24+
limit = 3
25+
assert Solution().numRescueBoats(people, limit) == 3
26+
27+
people = [3, 5, 3, 4]
28+
limit = 5
29+
assert Solution().numRescueBoats(people, limit) == 4
30+
31+
32+
if __name__ == '__main__':
33+
main()

2024-05-May-LeetCoding-Challenge/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
| May 1 | [2000. Reverse Prefix of Word](https://leetcode.com/problems/reverse-prefix-of-word/) | Easy | Solved |
77
| May 2 | [2441. Largest Positive Integer That Exists With Its Negative](https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/) | Easy | Solved |
88
| May 3 | [165. Compare Version Numbers](https://leetcode.com/problems/compare-version-numbers/) | Medium | Solved |
9-
| May 4 | []() | | |
9+
| May 4 | [881. Boats to Save People](https://leetcode.com/problems/boats-to-save-people/) | Medium | Solved |
1010
| May 5 | []() | | |
1111
| May 6 | []() | | |
1212
| May 7 | []() | | |
@@ -40,5 +40,5 @@
4040
| Level | Problems | Solved | Unsolved |
4141
| --- | --- | --- | --- |
4242
| Easy | 2 | 2 | 0 |
43-
| Medium | 0 | 0 | 0 |
43+
| Medium | 2 | 2 | 0 |
4444
| Hard | 0 | 0 | 0 |

0 commit comments

Comments
 (0)