mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-07 01:44:56 +08:00
16 lines
401 B
Go
16 lines
401 B
Go
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
|
|
}
|