Skip to content

Commit 4b1a22b

Browse files
committed
Runtime: 136 ms (Top 56.52%) | Memory: 53.8 MB (Top 73.91%)
1 parent 0047a7e commit 4b1a22b

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,43 @@
1+
// Runtime: 136 ms (Top 56.52%) | Memory: 53.8 MB (Top 73.91%)
12
var minimumRefill = function(plants, capacityA, capacityB) {
23
const n = plants.length;
3-
4+
45
let left = 0;
56
let right = n - 1;
6-
7+
78
let remA = capacityA;
89
let remB = capacityB;
9-
10+
1011
let refills = 0;
11-
12+
1213
while (left < right) {
1314
const leftAmount = plants[left++];
1415
const rightAmount = plants[right--];
15-
16+
1617
if (leftAmount > remA) {
1718
++refills;
1819
remA = capacityA;
1920
}
2021
remA -= leftAmount;
21-
22+
2223
if (rightAmount > remB) {
2324
++refills;
2425
remB = capacityB;
2526
}
2627
remB -= rightAmount;
27-
28+
2829
}
29-
30+
3031
if (left === right) {
3132
const midAmount = plants[left];
32-
33+
3334
if (remB > remA) {
3435
if (remB < midAmount) ++refills;
3536
}
3637
else {
3738
if (remA < midAmount) ++refills;
3839
}
3940
}
40-
41+
4142
return refills;
42-
};
43+
};

0 commit comments

Comments
 (0)