12345678910func maxProfit(prices []int) int { var income int for k := 0; (k + 1) < len(prices); k++ { //如果涨了,计算利润 if prices[k+1] > prices[k] { income += prices[k+1] - prices[k] } } return income}