We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b916321 commit df9998dCopy full SHA for df9998d
2105-watering-plants-ii.js
@@ -0,0 +1,33 @@
1
+/**
2
+ * @param {number[]} plants
3
+ * @param {number} capacityA
4
+ * @param {number} capacityB
5
+ * @return {number}
6
+ */
7
+const minimumRefill = function(plants, capacityA, capacityB) {
8
+ const n = plants.length
9
+ let [left, right] = [0, n - 1]
10
+ let [A, B] = [capacityA, capacityB]
11
+ let ans = 0
12
+ while (left < right) {
13
+ if (A < plants[left]) {
14
+ A = capacityA
15
+ ans += 1
16
+ }
17
+
18
+ A -= plants[left]
19
+ left += 1
20
+ if (B < plants[right]) {
21
+ B = capacityB
22
23
24
25
+ B -= plants[right]
26
+ right -= 1
27
28
29
30
+ if (left != right || A >= plants[left] || B >= plants[left]) return ans
31
+ return ans + 1
32
+};
33
0 commit comments