class Solution { public: int maxProfit(vector<int>& prices) { if (prices.size() == 0) return 0; int res = 0, _min = prices[0]; for (auto p : prices) { if (p < _min) _min = p; res = max(res, p - _min); } return res; } };