func 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
}
func 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
}
本文标题:122. 买卖股票的最佳时机 II
本文链接:https://www.haomeiwen.com/subject/fjahpktx.html
网友评论