Skip to content

Commit a68cd98

Browse files
committed
[LeetCode Sync] Runtime - 0 ms (100.00%), Memory - 17.6 MB (85.88%)
1 parent 82e7cb9 commit a68cd98

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

1642-water-bottles/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<p>There are <code>numBottles</code> water bottles that are initially full of water. You can exchange <code>numExchange</code> empty water bottles from the market with one full water bottle.</p>
2+
3+
<p>The operation of drinking a full water bottle turns it into an empty bottle.</p>
4+
5+
<p>Given the two integers <code>numBottles</code> and <code>numExchange</code>, return <em>the <strong>maximum</strong> number of water bottles you can drink</em>.</p>
6+
7+
<p>&nbsp;</p>
8+
<p><strong class="example">Example 1:</strong></p>
9+
<img alt="" src="https://assets.leetcode.com/uploads/2020/07/01/sample_1_1875.png" style="width: 500px; height: 245px;" />
10+
<pre>
11+
<strong>Input:</strong> numBottles = 9, numExchange = 3
12+
<strong>Output:</strong> 13
13+
<strong>Explanation:</strong> You can exchange 3 empty bottles to get 1 full water bottle.
14+
Number of water bottles you can drink: 9 + 3 + 1 = 13.
15+
</pre>
16+
17+
<p><strong class="example">Example 2:</strong></p>
18+
<img alt="" src="https://assets.leetcode.com/uploads/2020/07/01/sample_2_1875.png" style="width: 500px; height: 183px;" />
19+
<pre>
20+
<strong>Input:</strong> numBottles = 15, numExchange = 4
21+
<strong>Output:</strong> 19
22+
<strong>Explanation:</strong> You can exchange 4 empty bottles to get 1 full water bottle.
23+
Number of water bottles you can drink: 15 + 3 + 1 = 19.
24+
</pre>
25+
26+
<p>&nbsp;</p>
27+
<p><strong>Constraints:</strong></p>
28+
29+
<ul>
30+
<li><code>1 &lt;= numBottles &lt;= 100</code></li>
31+
<li><code>2 &lt;= numExchange &lt;= 100</code></li>
32+
</ul>

1642-water-bottles/solution.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Solution:
2+
def numWaterBottles(self, n: int, x: int) -> int:
3+
return n + (n - 1) // (x - 1)

0 commit comments

Comments
 (0)