https://leetcode.com/problems/best-time-to-buy-and-sell-stock/
class Solution {
public:
int maxProfit(vector<int>& prices) {
int len = prices.size();
if(len == 0)
return 0;
int profit = 0,low = prices[0];//low记录当前最小的股价
for(int i = 1;i < len;i++){
if(prices[i] < low)//一旦发现更小的股价,更新
low = prices[i];
else
if(prices[i] - low > profit)
profit = prices[i] - low;
}
return profit;
}
};