Leetcode 1518 换酒问题
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; };
当你看清人们的真相,于是你知道了,你可以忍受孤独