LC 121. Best Time to Buy and Sell Stock

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
/**
 * @param {number[]} prices
 * @return {number}
 */
var maxProfit = function(prices) {
  if (prices.length === 0) return 0
  let min = prices[0]
  let max = 0
  for (let p of prices) {
    min = Math.min(min, p)
    max = Math.max(max, p - min)
  }
  return max
};





评论和交流请发送邮件到 me@tianhegao.com





通过以下渠道赞赏此文