Me
输入: [7,1,5,3,6,4]
输出: 7
输入: [1,2,3,4,5]
输出: 4
输入: [7,6,4,3,1]
输出: 0
得出的结论就是当有了股票只要明天跌就今天卖。只要明天涨今天就买(只限于做题???)
func maxProfit(prices []int) int {
res := 0
for i:=1; i < len(prices); i++ {
if prices[i] > prices[i-1] {
res += prices[i] -prices[i-1]
}
}
return res
}