Same idea as always: (just subtract fee)


  • 0
    L
    int maxProfit(vector<int>& prices, int fee) {
        int profit = 0, balance = INT_MIN;
        for(int x : prices)
            balance = max(balance, profit-x),
            profit = max(profit, balance+x-fee);
        return profit;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.