当前位置 : 主页 > 手机开发 > harmonyos >

leetcode-714-Best Time to Buy and Sell Stock with Transaction Fee

来源:互联网 收集:自由互联 发布时间:2023-08-26
error: use DP. In i-th day, we can buy or sell, so we have two status: buy[i] or sell[i]. Each stands for the max profit if we buy/sell. So: sell[i] = max(sell[i - 1], sell[i - 1] + prices[i] + fee) buy[i] = max(buy[i - 1], buy[i - 1] + pri


error:
use DP. In i-th day, we can buy or sell, so we have two status: buy[i] or sell[i]. Each stands for the max profit if we buy/sell. So:

sell[i] = max(sell[i - 1], sell[i - 1] + prices[i] + fee)
buy[i] = max(buy[i - 1], buy[i - 1] + prices[i])

initial: sell[0] = 0; buy[0] = -prices[0];

Learn: deride the equation from actions and not from days or times


上一篇:leetcode-377-Combination Sum IV
下一篇:没有了
网友评论