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 2bc42e6 commit 41b9640Copy full SHA for 41b9640
container-with-most-water/Cyjin-jani.js
@@ -0,0 +1,22 @@
1
+// tc: O(n);
2
+// sc: O(1);
3
+const maxArea = function (height) {
4
+ let max = 0;
5
+ let leftIdx = 0;
6
+ let rightIdx = height.length - 1;
7
+
8
+ while (leftIdx < rightIdx) {
9
+ const width = rightIdx - leftIdx;
10
+ const minHeight = Math.min(height[leftIdx], height[rightIdx]);
11
+ const area = width * minHeight;
12
+ max = Math.max(max, area);
13
14
+ if (height[leftIdx] > height[rightIdx]) {
15
+ rightIdx -= 1;
16
+ } else {
17
+ leftIdx += 1;
18
+ }
19
20
21
+ return max;
22
+};
0 commit comments