classSolution { public: intmaxProfit(vector<int>& prices){ if (prices.size() == 0) { return0; } int mi = prices[0]; int ans = 0; for (int i = 1; i < prices.size(); i++) { if (prices[i] - mi > 0) { ans += prices[i] - mi; mi = prices[i]; } mi = min(mi, prices[i]); } return ans; } };