Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int maxProfit(vector<int>& prices) {
- int sold = INT_MIN, hold = INT_MIN, rest=0;
- for(int price: prices){
- int presold = sold;
- sold = hold+price;
- hold = max(hold, rest-price);
- rest = max(rest, presold);
- }
- return max(sold, rest);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement