diff --git a/go/121-Best-Time-To-Buy-And-Sell-Stock.go b/go/121-Best-Time-To-Buy-And-Sell-Stock.go new file mode 100644 index 000000000..45c110191 --- /dev/null +++ b/go/121-Best-Time-To-Buy-And-Sell-Stock.go @@ -0,0 +1,16 @@ +func maxProfit(prices []int) int { + min := math.MaxUint32 + res := 0 + + for _, price := range prices { + if price > min { + if price-min > res { + res = price - min + } + } else { + min = price + } + } + + return res +} \ No newline at end of file