2706. 购买两块巧克力

2706. 购买两块巧克力

解法一: 一次遍历

go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
func buyChoco(prices []int, money int) int {
first := 100
second := 100
for _, price := range prices {
if first > price {
second = first
first = price
} else if second > price {
second = price
}
}
if first + second > money {
return money
}
return money - first - second
}
作者

wuhunyu

发布于

2023-12-29

更新于

2023-12-29

许可协议