Участник:Ковальков Антон М05-903б/Best Time to Buy and Sell Stock with Transaction Fee

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



class Solution:
    def maxProfit(self, prices: List[int], fee: int) -> int:
        curr_buy = prices[0] + fee
        res = 0
        for i in range(1, len(prices)):
            if prices[i] + fee < curr_buy:
                curr_buy = prices[i] + fee
            if prices[i] > curr_buy:
                res += prices[i] - curr_buy
                curr_buy = prices[i]
        return res