Skip to content

Commit c776aeb

Browse files
add 1518
1 parent d4e4d6d commit c776aeb

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1518|[Water Bottles](https://leetcode.com/problems/water-bottles/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1518.java) | |Easy|Greedy|
1112
|1514|[Path with Maximum Probability](https://leetcode.com/problems/path-with-maximum-probability/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1514.java) | |Medium|Graph|
1213
|1512|[Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1512.java) | |Easy|Array, HashTable, Math|
1314
|1508|[Range Sum of Sorted Subarray Sums](https://leetcode.com/problems/range-sum-of-sorted-subarray-sums/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1508.java) | |Medium|Array, Sort|
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _1518 {
4+
public static class Solution1 {
5+
public int numWaterBottles(int numBottles, int numExchange) {
6+
int drunk = numBottles;
7+
int emptyBottles = numBottles;
8+
while (emptyBottles >= numExchange) {
9+
int exchangedBottles = emptyBottles / numExchange;
10+
drunk += exchangedBottles;
11+
int unUsedEmptyBottles = emptyBottles % numExchange;
12+
emptyBottles = exchangedBottles + unUsedEmptyBottles;
13+
}
14+
return drunk;
15+
}
16+
}
17+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1518;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static junit.framework.TestCase.assertEquals;
8+
9+
public class _1518Test {
10+
private static _1518.Solution1 solution1;
11+
12+
@BeforeClass
13+
public static void setup() {
14+
solution1 = new _1518.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(13, solution1.numWaterBottles(9, 3));
20+
}
21+
22+
}

0 commit comments

Comments
 (0)