We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3ae0b64 commit 5df74a7Copy full SHA for 5df74a7
boats-to-save-people.go
@@ -0,0 +1,27 @@
1
+package main
2
+
3
+import "sort"
4
5
+// 881 https://leetcode-cn.com/problems/boats-to-save-people/
6
+// 贪心
7
+func numRescueBoats(people []int, limit int) (ans int) {
8
+ sort.Ints(people)
9
10
+ light, heavy := 0, len(people)-1
11
+ for light <= heavy {
12
+ if people[heavy] == limit {
13
+ ans++
14
+ heavy--
15
+ continue
16
+ }
17
+ if people[light]+people[heavy] > limit {
18
19
+ } else {
20
21
+ light++
22
23
24
25
26
+ return
27
+}
0 commit comments