1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| // @Title: 股票的最大利润 (股票的最大利润 LCOF)
// @Author: 15816537946@163.com
// @Date: 2022-02-13 09:58:32
// @Runtime: 4 ms
// @Memory: 2.9 MB
func maxProfit(prices []int) int {
minNum := 1 << 31
var maxProfit int
for _, v := range prices {
if v < minNum {
minNum = v
} else if v - minNum > maxProfit {
maxProfit = v -minNum
}
}
return maxProfit
}
|