力扣 1518. 换酒问题 难度:简单
作者:互联网
题目地址: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; } }
标签:瓶子,int,力扣,numExchange,1518,换酒,numBottles,total,数量 来源: https://www.cnblogs.com/zhangmuchen/p/15701798.html