class Solution {
public int maxProfit(int[] prices, int fee) {
int[][] dp = new int[prices.length + 1][2];
dp[0][0]= -prices[0] - fee;
for(int i = 1; i < prices.length + 1;i++){
int price = prices[i - 1];
dp[i][0] = Math.max(Math.max(dp[i - 1][1] - price - fee,dp[i - 1][0]),- price - fee);
dp[i][1] = Math.max(dp[i - 1][0] + price,dp[i - 1][1]);
}
return dp[prices.length][1];
}
}
714. 买卖股票的最佳时机含手续费
最新推荐文章于 2024-06-13 08:37:22 发布