买卖股票的最佳时机记录最低的价格,每次计算最大的利润,返回即可 12345678910111213/** * @param {number[]} prices * @return {number} */var maxProfit = function (prices) { let minPrice = prices[0]; let maxProfitNum = 0; for (let i = 1; i < prices.length; i++) { minPrice = Math.min(minPrice, prices[i]); maxProfitNum = Math.max(maxProfitNum, prices[i] - minPrice); } return maxProfitNum;};