#1518

Water Bottles

newbie · 260 · lc easy +19 · verified · 72.6% accepted · 2,266 likes · top 82%

Description

You start with numBottles full water bottles. Drinking a full bottle produces one empty bottle, and you can trade numExchange empty bottles for one full bottle. Return the maximum total number of bottles you can drink.

Example 1:

Input: numBottles = 9, numExchange = 3
Output: 13
Explanation: You can exchange 3 empty bottles to get 1 full water bottle.
Number of water bottles you can drink: 9 + 3 + 1 = 13.

Example 2:

Input: numBottles = 15, numExchange = 4
Output: 19
Explanation: You can exchange 4 empty bottles to get 1 full water bottle.
Number of water bottles you can drink: 15 + 3 + 1 = 19.

Code

1
2
3