Water Bottles
给一个数字表示汽水的个数, 另一个表示喝完后空瓶换新需要的比例. 求一共能喝几瓶.
模拟一下
class Solution {
public int numWaterBottles(int numBottles, int numExchange) {
int res = 0;
int empty = 0;
do {
res += numBottles;
empty += numBottles;
int newNumBottles = empty / numExchange;
empty %= numExchange;
numBottles = newNumBottles;
} while(numBottles > 0);
return res;
}
}