如上图所示 A+B>=C (D不存在的情况下A+B=C)
只要找到所有 后面比前面高的点 就可以了(动态规划…?)
var maxProfit = function (prices) {
let profit = 0;
for (let i = 1; i < prices.length; i++) {
if(prices[i]>prices[i-1]){
profit = profit + prices[i] - prices[i-1]
}
}
return profit
};