1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| // @Title: 买卖股票的最佳时机 II (Best Time to Buy and Sell Stock II)
// @Author: 15816537946@163.com
// @Date: 2019-11-17 17:45:53
// @Runtime: 4 ms
// @Memory: 3 MB
func maxProfit(prices []int) int {
if len(prices) == 0 {
return 0
}
var profile int
for i := 1;i< len(prices);i++ {
if prices[i] - prices[i-1] > 0 {
profile += prices[i]-prices[i-1]
}
}
return profile
}
|