码迷,mamicode.com
首页 > 其他好文 > 详细

Leetcode 1518 换酒问题

时间:2021-05-24 03:39:54      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:fun   问题   return   mat   col   blog   floor   exchange   rgba   

技术图片 

  JAVA:

public final int numWaterBottles(int numBottles, int numExchange) {
        int re = numBottles, empty = numBottles;
        while (empty >= numExchange) {
            int newBeer = empty / numExchange;
            re += newBeer;
            empty = empty % numExchange + newBeer;
        }
        return re;
    }

  JS:

/**
 * @param {number} numBottles
 * @param {number} numExchange
 * @return {number}
 */
var numWaterBottles = function (numBottles, numExchange) {
    let re = numBottles, empty = numBottles;
    while (empty >= numExchange) {
        let newBeer = Math.floor(empty / numExchange);
        re += newBeer;
        empty = empty % numExchange + newBeer;
    }
    return re;
};

技术图片

 

Leetcode 1518 换酒问题

标签:fun   问题   return   mat   col   blog   floor   exchange   rgba   

原文地址:https://www.cnblogs.com/niuyourou/p/14749106.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!