股票的最佳买入卖出时间
一开始我用两个循环,如果只用一个循环的话:
int maxProfit(vector<int>& prices) {
size_t size = prices.size();
if (size <= 1) return 0;
int min = INT_MAX, max = INT_MIN;
for (int i = 0; i < size; ++i) {
if (prices[i] < min)
min = prices[i];
if (max < prices[i] - min)
max = prices[i] - min;
}
return max;