题目描述:
首刷自解:
int maxProfit(vector<int>& prices) {
int maxProfit = 0, buyInDay = prices[0];
for (const auto& iter : prices)
{
if (iter < buyInDay)
buyInDay = iter;
maxProfit = max(maxProfit, iter - buyInDay);
}
return maxProfit;
}