leetCode-Record
leetCode-Record copied to clipboard
面试题63. 股票的最大利润
dp问题:
/**
* @param {number[]} prices
* @return {number}
*/
var maxProfit = function(prices) {
if(prices.length < 0) {
return;
}
let sum = prices[0];
let dp = [];
dp[0] = 0;
for(let i = 1;i<prices.length;i++){
dp[i] = Math.max(dp[i-1],prices[i]-sum);
if(sum > prices[i]){
sum = prices[i];
}
}
dp.sort((a,b)=>b-a);
return dp[0];
};