File tree 2 files changed +33
-1
lines changed
2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,342 LeetCode solutions in JavaScript
1
+ # 1,343 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1159
1159
1513|[ Number of Substrings With Only 1s] ( ./solutions/1513-number-of-substrings-with-only-1s.js ) |Medium|
1160
1160
1514|[ Path with Maximum Probability] ( ./solutions/1514-path-with-maximum-probability.js ) |Medium|
1161
1161
1515|[ Best Position for a Service Centre] ( ./solutions/1515-best-position-for-a-service-centre.js ) |Hard|
1162
+ 1518|[ Water Bottles] ( ./solutions/1518-water-bottles.js ) |Easy|
1162
1163
1519|[ Number of Nodes in the Sub-Tree With the Same Label] ( ./solutions/1519-number-of-nodes-in-the-sub-tree-with-the-same-label.js ) |Medium|
1163
1164
1524|[ Number of Sub-arrays With Odd Sum] ( ./solutions/1524-number-of-sub-arrays-with-odd-sum.js ) |Medium|
1164
1165
1528|[ Shuffle String] ( ./solutions/1528-shuffle-string.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1518. Water Bottles
3
+ * https://leetcode.com/problems/water-bottles/
4
+ * Difficulty: Easy
5
+ *
6
+ * There are numBottles water bottles that are initially full of water. You can exchange numExchange
7
+ * empty water bottles from the market with one full water bottle.
8
+ *
9
+ * The operation of drinking a full water bottle turns it into an empty bottle.
10
+ *
11
+ * Given the two integers numBottles and numExchange, return the maximum number of water bottles you
12
+ * can drink.
13
+ */
14
+
15
+ /**
16
+ * @param {number } numBottles
17
+ * @param {number } numExchange
18
+ * @return {number }
19
+ */
20
+ var numWaterBottles = function ( numBottles , numExchange ) {
21
+ let result = numBottles ;
22
+ let emptyBottles = numBottles ;
23
+
24
+ while ( emptyBottles >= numExchange ) {
25
+ const newBottles = Math . floor ( emptyBottles / numExchange ) ;
26
+ result += newBottles ;
27
+ emptyBottles = newBottles + ( emptyBottles % numExchange ) ;
28
+ }
29
+
30
+ return result ;
31
+ } ;
You can’t perform that action at this time.
0 commit comments