Boats to Save People
Thei
-th person has weightpeople[i]
, and each boat can carry a maximum weight oflimit
.
Each boat carries at most 2 people at the same time, provided the sum of the weight of those people is at mostlimit
.
Return the minimum number of boats to carry every given person. (It is guaranteed each person can be carried by a boat.)
Example 1:
Example 2:
Example 3:
Note:
分析
因为船只能载2人每次,所以可以双指针夹逼,注意是 l<=r
Last updated
Was this helpful?