Skip to content

Commit d795322

Browse files
committed
881/go
1 parent 168116b commit d795322

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

881.boats-to-save-people.0.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* @lc app=leetcode id=881 lang=golang
3+
*
4+
* [881] Boats to Save People
5+
*/
6+
import "sort"
7+
func numRescueBoats(people []int, limit int) int {
8+
sort.Ints(people)
9+
count, l, r := 0, 0, len(people) - 1
10+
for l <= r {
11+
if people[r] > limit {
12+
continue
13+
}
14+
count++
15+
if people[r] >= limit || people[r] + people[l] > limit {
16+
r--
17+
continue
18+
}
19+
r--
20+
l++
21+
}
22+
23+
return count
24+
}

0 commit comments

Comments
 (0)