There was an error while loading. Please reload this page.
1 parent 9623b8a commit d6d547cCopy full SHA for d6d547c
1518-water-bottles/1518-water-bottles.ts
@@ -0,0 +1,10 @@
1
+const numWaterBottles = (numBottles: number, numExchange: number): number => {
2
+ let ans = numBottles;
3
+ let empty = numBottles;
4
+ while (empty >= numExchange) {
5
+ const full = Math.floor(empty / numExchange);
6
+ ans += full;
7
+ empty = full + empty % numExchange;
8
+ }
9
+ return ans;
10
+};
0 commit comments