增加新题目

This commit is contained in:
JACKYMYPERSON
2025-09-01 20:17:03 +08:00
parent 72f4dca9ed
commit 14a6771b9a
7 changed files with 188 additions and 4 deletions

View File

@@ -0,0 +1,26 @@
package main
func main() {
}
func maxProfit(prices []int) int {
minnum := 0
res := 0
for i := 0; i < len(prices); i++ {
if i == 0 {
minnum = prices[i]
res = 0
continue
}
if prices[i] < minnum {
minnum = prices[i]
}
tmpnum := prices[i] - minnum
if tmpnum > res {
res = tmpnum
}
}
return res
}