majianyu
3/11/2019 - 5:41 PM

122 买入股票的最佳时机 II

计算数组中相邻两个元素,差值为正数的参与求和

func maxProfit(prices []int) int {
    res := 0
	for i:=0;i<len(prices)-1;i++ {
		diff := prices[i+1] - prices[i]
		if diff > 0 {
			res += diff
		}
	}
	return res
    
}