题目地址:https://leetcode-cn.com/problems/water-bottles/
我的答案:
class Solution { public int numWaterBottles(int numBottles, int numExchange) { /** numBottles为购买数量 numExchange为多少个空瓶子可以交换新瓶子的数量 total 共计得到的新瓶子数 */int total = numBottles; //当空瓶子小于规定交换瓶子数量时就无法获取新瓶子 while(numBottles>=numExchange){ total += numBottles/numExchange; numBottles = (numBottles/numExchange) + (numBottles%numExchange); } return total; } }