121.买股票的最佳时机力扣第121、160题 121.买股票的最佳时机贪心思想,取最左最小的,再取右边相差区间最大的 var maxProfit = function(prices) { let low = Infinity let res = 0 for(let i = 0; i<prices.length;i++){ low = Math.min(low,prices[i]) res = Math.max(res,prices[i]-low) } return res;};