/*
* @lc app=leetcode.cn id=121 lang=javascript
*
* [121] 买卖股票的最佳时机
*/
// @lc code=start
/**
* @param {number[]} prices
* @return {number}
*/
var maxProfit = function (prices) {
let max = 0;
let min = Number.MAX_VALUE;
for (let price of prices) {
if (price < min) {
min = price;
continue;
}
max = Math.max(max, price - min)
}
return max;
};
// @lc code=end
console.log(maxProfit([7, 1, 5, 3, 6, 4]))
console.log(maxProfit([7, 6, 4, 3, 1]))