leetcode121_买卖股票的最佳时机
public int maxProfit(int[] prices) {
if(prices.length < 2) return 0;
int ans = 0, beforeMin = prices[0];
for(int i =1; i < prices.length; i++) {
int profit = prices[i] - beforeMin;
if( profit > 0) ans = Math.max(ans, prices[i] - beforeMin);
beforeMin = Math.min(beforeMin, prices[i]);
}
return ans;
}