1. 程式人生 > 其它 >#力扣 LeetCode1518. 換酒問題 @FDDLC

#力扣 LeetCode1518. 換酒問題 @FDDLC

技術標籤:演算法&資料結構

題目描述:

https://leetcode-cn.com/problems/water-bottles/

Java程式碼:

class Solution {
    public int numWaterBottles(int sum, int deal) {
        int ans=sum;
        while(sum>=deal){
            ans+=sum/deal;
            sum=sum%deal+sum/deal;
        }
        return ans;
    }
}