1 2 3 4 5 6 7 8 9 10 11
| class Solution { public: int maxProfit(vector<int>& prices) { int min_price = INT_MAX, max_profit = 0; for (int price : prices) { max_profit = max(max_profit, price - min_price); min_price = min(min_price, price); } return max_profit; } };
|