力扣 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;
}
}
本文来自博客园,作者:宗神一,转载请注明原文链接:https://www.cnblogs.com/zhangmuchen/p/15701798.html