diff --git a/0714-best-time-to-buy-and-sell-stock-with-transaction-fee/0714-best-time-to-buy-and-sell-stock-with-transaction-fee.go b/0714-best-time-to-buy-and-sell-stock-with-transaction-fee/0714-best-time-to-buy-and-sell-stock-with-transaction-fee.go index d4f8ea5..fd07c01 100644 --- a/0714-best-time-to-buy-and-sell-stock-with-transaction-fee/0714-best-time-to-buy-and-sell-stock-with-transaction-fee.go +++ b/0714-best-time-to-buy-and-sell-stock-with-transaction-fee/0714-best-time-to-buy-and-sell-stock-with-transaction-fee.go @@ -1,19 +1,11 @@ func maxProfit(prices []int, fee int) int { dp := make([][2]int, len(prices)) - dp[0][1] = -prices[0] - + dp[0][1] = - prices[0] + for i := 1; i < len(prices); i++ { dp[i][0] = max(dp[i-1][0], prices[i] + dp[i-1][1] - fee) dp[i][1] = max(dp[i-1][1], dp[i-1][0] - prices[i]) } - + return dp[len(prices) - 1][0] } - -func max(a, b int) int { - if a > b { - return a - } - - return b -} \ No newline at end of file