0
点赞
收藏
分享

微信扫一扫

LEETCODE 1599. 经营摩天轮的最大利润

这道题乍一看很复杂,其实仔细阅读后发现去模拟就可以

需要注意的点是大循环是当前人数大于0,但是有可能第一批人数为0,因此在循环里还没遍历完customers数组时也要进入循环

class Solution:
def minOperationsMaxProfit(self, customers: List[int], boardingCost: int, runningCost: int) -> int:
n=customers[0]
s=0
l=0
j=1
b=-1
while n>0 or j-1<len(customers):
if n<4:
s+=n
n=0
else:
s+=4
n-=4

if s*boardingCost-j*runningCost>l :
b=j
l=s*boardingCost-j*runningCost


if j<len(customers):
n+=customers[j]
j+=1
return b


举报

相关推荐

0 条评论