Posted on

Description

Submission

class Solution {
public:
    int maxProfit(vector<int>& prices, int fee) {
        int hold = INT_MIN / 2, sold = 0;

        for(int p: prices) {
            int prevHold = hold, prevSold = sold;
            hold = max(prevHold, prevSold - p);
            sold = max(prevSold, prevHold + p - fee);
        }

        return sold;
    }
};

// hold = max(prevHold, prevSold);
// sold = prevSold + p - 2;

Leave a Reply

Your email address will not be published. Required fields are marked *