add: leetcode 1518 solution

This commit is contained in:
tphyhFighting
2021-12-17 10:45:20 +08:00
parent a3c7d4247c
commit a3328f0d7f

View File

@ -0,0 +1,15 @@
package leetcode
func numWaterBottles(numBottles int, numExchange int) int {
if numBottles < numExchange {
return numBottles
}
quotient := numBottles / numExchange
reminder := numBottles % numExchange
ans := numBottles + quotient
for quotient+reminder >= numExchange {
quotient, reminder = (quotient+reminder)/numExchange, (quotient+reminder)%numExchange
ans += quotient
}
return ans
}