714. Best Time to Buy and Sell Stock with Transaction Fee

714. Best Time to Buy and Sell Stock with Transaction Fee

class Solution:
    def maxProfit(self, prices: List[int], fee: int) -> int:
        buy=float(-inf)
        sell=0

        for p in prices:
            buy=max(buy,sell-p)
            sell=max(sell,buy+p-fee)
            # print(buy,sell)
        return sell

LeetCode - The World's Leading Online Programming Learning Platform

你可能感兴趣的:(leetcode)