mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-10 00:09:06 +01:00
17 lines
284 B
Go
17 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
|
||
|
}
|