题解 | #买卖股票的最好时机#
买卖股票的最好时机
http://www.nowcoder.com/practice/64b4262d4e6d4f6181cd45446a5821ec
let max = 0
let a =0
let b
for(let i =2 ;i<=prices.length;i++) {
if(a >=0 && prices[i-1] - prices[i-2] >=0) {
b =a + prices[i-1] - prices[i-2]
}else{
b = Math.max(a+ prices[i-1] - prices[i-2],0)
}
max = Math.max(b,max)
a = b
}
return max