1642. Water Bottles
My accepted Python solution to LeetCode problem 1642, Water Bottles, running in 0ms.
- Difficulty: Easy
- Python
- Runtime 0ms
- Memory 17.6MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 0ms, memory 17.6MB, accepted 2025-12-24.
class Solution:
def numWaterBottles(self, numBottles: int, numExchange: int) -> int:
total = numBottles
empty = numBottles
while empty >= numExchange:
new_bottles = empty // numExchange
total += new_bottles
empty = empty % numExchange + new_bottles
return total