diff --git a/problems/0714.买卖股票的最佳时机含手续费.md b/problems/0714.买卖股票的最佳时机含手续费.md index 964d5ea9..f7ddeaf7 100644 --- a/problems/0714.买卖股票的最佳时机含手续费.md +++ b/problems/0714.买卖股票的最佳时机含手续费.md @@ -195,22 +195,6 @@ class Solution { // 动态规划 } ``` -```java -// 一维数组优化 -class Solution { - public int maxProfit(int[] prices, int fee) { - int[] dp = new int[2]; - dp[0] = -prices[0]; - dp[1] = 0; - for (int i = 1; i <= prices.length; i++) { - dp[0] = Math.max(dp[0], dp[1] - prices[i - 1]); - dp[1] = Math.max(dp[1], dp[0] + prices[i - 1] - fee); - } - return dp[1]; - } -} -``` - Python: diff --git a/problems/0714.买卖股票的最佳时机含手续费(动态规划).md b/problems/0714.买卖股票的最佳时机含手续费(动态规划).md index 2b3416d4..700b8cde 100644 --- a/problems/0714.买卖股票的最佳时机含手续费(动态规划).md +++ b/problems/0714.买卖股票的最佳时机含手续费(动态规划).md @@ -134,6 +134,20 @@ public int maxProfit(int[] prices, int fee) { } return Math.max(dp[len - 1][0], dp[len - 1][1]); } + +// 一维数组优化 +class Solution { + public int maxProfit(int[] prices, int fee) { + int[] dp = new int[2]; + dp[0] = -prices[0]; + dp[1] = 0; + for (int i = 1; i <= prices.length; i++) { + dp[0] = Math.max(dp[0], dp[1] - prices[i - 1]); + dp[1] = Math.max(dp[1], dp[0] + prices[i - 1] - fee); + } + return dp[1]; + } +} ``` Python: