From 9885ede0c5c6394f0196b2e7d459105d77749c07 Mon Sep 17 00:00:00 2001 From: Jack Sangdahl Date: Tue, 30 Sep 2025 21:49:16 -0600 Subject: 1518. water bottles --- water_bottles.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'water_bottles.c') diff --git a/water_bottles.c b/water_bottles.c index 20a0a2d..6f11346 100644 --- a/water_bottles.c +++ b/water_bottles.c @@ -10,14 +10,7 @@ */ int numWaterBottles(int numBottles, int numExchange) { - int ans = numBottles; - while (numBottles >= numExchange) { - int rem = numBottles % numExchange; - numBottles /= numExchange; - ans += numBottles; - numBottles += rem; - } - return ans; + return numBottles + (numBottles - 1) / (numExchange - 1); } int main() { -- cgit v1.2.3