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