计算数组中相邻两个元素,差值为正数的参与求和
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 }