Timeline
Timeline
2025-10-01
init
Math, Simulation
Problem:
A simple math simulation problem
12345678910111213141516171819 | class Solution {public: int numWaterBottles(int numBottles, int numExchange) { // Every numExchange bottles consumed can be exchanged for one bottle int exchange_bootles = -1; int total_water = 0; do { exchange_bootles = numBottles / numExchange; numBottles = numBottles % numExchange; numBottles += exchange_bootles; total_water += exchange_bootles * numExchange; } while (numBottles >= numExchange); total_water += numBottles; return total_water; }}; |
