2024-07-07
1518. Water Bottles
There are numBottles water bottles that are initially full of water. You can
exchange numExchange empty water bottles from the market with one full water
bottle.
The operation of drinking a full water bottle turns it into an empty bottle.
Given the two integers numBottles and numExchange, return the maximum number
of water bottles you can drink.
暴力解
每次多喝 B 瓶
每 E 个空瓶可以去换一瓶满的
会剩下 R 个空瓶
int numWaterBottles(int numBottles, int numExchange) {
int count = numBottles;
int rest = 0;
int tmp_numBottles = 0;
while (numBottles + rest >= numExchange) {
tmp_numBottles = (numBottles + rest) / numExchange;
rest = (numBottles + rest) % numExchange;
count += tmp_numBottles;
numBottles = tmp_numBottles;
}
return count;
}
一行的数学姐看不懂
有大师能用姆咪也看得懂的方式解释一下吗
[Python] One line Math Solution O(1) beating 100%