Участник:Plague rat/Best Time to Buy and Sell Stock with Transaction Fee

Материал из DISCOPAL
Перейти к: навигация, поиск

https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee/

class Solution:
    def maxProfit(self, prices: List[int], fee: int) -> int:
        profit = [[0] * len(prices) for i in range(2)]
        profit[0][0] = -prices[0] - fee
 
        for i in range(1, len(prices)):
            profit[0][i] = max(profit[0][i - 1], profit[1][i - 1] - prices[i] - fee)
            profit[1][i] = max(profit[1][i - 1], profit[0][i - 1] + prices[i])
 
        return max(profit[0][len(prices) - 1], profit[1][len(prices) - 1])