题目描述
超市正在促销,你可以用 numExchange 个空水瓶从超市兑换一瓶水。最开始,你一共购入了numBottles 瓶水。如果喝掉了水瓶中的水,那么水瓶就会变成空的。给你两个整数 numBottles 和 numExchange ,返回你 最多 可以喝到多少瓶水。
代码
class Solution {
public int numWaterBottles(int numBottles, int numExchange) {
int ans = numBottles, cup = numBottles;
while(cup>=numExchange){
int add = cup/numExchange;
ans += add;
cup = cup%numExchange + add;
}
return ans;
}
}