class Solution {
public:
int maxProfit(vector<int>& prices) {
if (prices.size() == 0) {
return 0;
}
int least = prices[0], maxPrice = 0;
for (int i = 0; i < prices.size(); i++) {
least = min(least, prices[i]);
maxPrice = max(maxPrice, prices[i] - least);
}
return maxPrice;
}
};