Files
practice/pkg/best_time_to_buy_and_sell_stock/main.go
2026-01-23 23:11:32 -05:00

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
}