12 lines
205 B
Go
12 lines
205 B
Go
package besttimetobuyandsellstock
|
|
|
|
func MaxProfit(prices []int) int {
|
|
buy, sell := 1_000_000_000, 0
|
|
|
|
for _, price := range prices {
|
|
buy, sell = min(buy, price), max(sell, price-buy)
|
|
}
|
|
|
|
return sell
|
|
}
|