1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-09-19 01:36:57 +02:00

go: add «1518. Water Bottles»

Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2024-07-07 17:15:52 +02:00
parent e4dbf828e0
commit 3b9a63195b
Signed by: mfocko
SSH key fingerprint: SHA256:5YXD7WbPuK60gxnG6DjAwJiS9+swoWj33/HFu8g8JVo

16
go/water-bottles.go Normal file
View file

@ -0,0 +1,16 @@
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
}