/**
* @param {number[]} prices
* @return {number}
*/
var maxProfit = function (prices) {
// dp[i] = dp[i-1] + i;
let min = Number.MAX_SAFE_INTEGER,
res = 0;
for (let i = 0; i < prices.length; i++) {
let cur = prices[i];
if (cur < min) {
min = cur;
}
if (cur - min > res) {
res = cur - min;
}
}
return res;
};