mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-06 17:44:10 +08:00
add: leetcode 1518 solution
This commit is contained in:
15
leetcode/1518.Water-Bottles/1518.Water Bottles.go
Normal file
15
leetcode/1518.Water-Bottles/1518.Water Bottles.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user