LeetCode 1518 换酒问题[模拟] HERODING的LeetCode之路

Posted HERODING23

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode 1518 换酒问题[模拟] HERODING的LeetCode之路相关的知识,希望对你有一定的参考价值。


解题思路:
可以说是最简单的模拟题目了,以当前酒瓶子数为基准,然后不断用空瓶子换酒,注意酒可以产生一个新的空瓶子,直到无法兑换,代码如下:

class Solution 
public:
    int numWaterBottles(int numBottles, int numExchange) 
        int sum = numBottles;
        int empty = numBottles;
        while(empty >= numExchange) 
            empty -= numExchange;
            sum ++;
            empty ++;
        
        return sum;
    
;

以上是关于LeetCode 1518 换酒问题[模拟] HERODING的LeetCode之路的主要内容,如果未能解决你的问题,请参考以下文章