diff --git a/problems/0714.买卖股票的最佳时机含手续费(动态规划).md b/problems/0714.买卖股票的最佳时机含手续费(动态规划).md index 5eb3453b..e2b83999 100644 --- a/problems/0714.买卖股票的最佳时机含手续费(动态规划).md +++ b/problems/0714.买卖股票的最佳时机含手续费(动态规划).md @@ -153,7 +153,18 @@ class Solution: Go: - +Javascript: +```javascript +const maxProfit = (prices,fee) => { + let dp = Array.from(Array(prices.length), () => Array(2).fill(0)); + dp[0][0] = 0 - prices[0]; + for (let i = 1; i < prices.length; i++) { + dp[i][0] = Math.max(dp[i - 1][0], dp[i - 1][1] - prices[i]); + dp[i][1] = Math.max(dp[i - 1][0] + prices[i] - fee, dp[i - 1][1]); + } + return Math.max(dp[prices.length - 1][0], dp[prices.length - 1][1]); +} +``` -----------------------