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;