mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-09 15:59:06 +01:00
go: add «1518. Water Bottles»
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
e4dbf828e0
commit
3b9a63195b
1 changed files with 16 additions and 0 deletions
16
go/water-bottles.go
Normal file
16
go/water-bottles.go
Normal 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
|
||||
}
|
Loading…
Reference in a new issue