We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3e99718 commit e5a39efCopy full SHA for e5a39ef
container-with-most-water/evan.js
@@ -0,0 +1,23 @@
1
+/**
2
+ * @param {number[]} heights
3
+ * @return {number}
4
+ */
5
+var maxArea = function (heights) {
6
+ let maxAmount = 0;
7
+ let [leftEnd, rightEnd] = [0, heights.length - 1];
8
+
9
+ while (leftEnd < rightEnd) {
10
+ const minHeight = Math.min(heights[leftEnd], heights[rightEnd]);
11
+ const horizontalLength = rightEnd - leftEnd;
12
13
+ maxAmount = Math.max(maxAmount, minHeight * horizontalLength);
14
15
+ if (heights[leftEnd] > heights[rightEnd]) {
16
+ rightEnd -= 1;
17
+ } else {
18
+ leftEnd += 1;
19
+ }
20
21
22
+ return maxAmount;
23
+};
0 commit comments