LeetCode/go/water-bottles.go
Matej Focko 3b9a63195b
go: add «1518. Water Bottles»
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-07-07 17:15:52 +02:00

16 lines
284 B
Go

package main
func numWaterBottles(numBottles int, numExchange int) int {
drank := 0
for numBottles >= numExchange {
canGet := numBottles / numExchange
drank += canGet * numExchange
numBottles -= canGet * numExchange
numBottles += canGet
}
return drank + numBottles
}