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 3a537d5Copy full SHA for 3a537d5
container-with-most-water/nhistory.js
@@ -0,0 +1,23 @@
1
+var maxArea = function (height) {
2
+ // Two pointer: left and right
3
+ // Amount of water: math.Min(height[left], height[right]) * (right-left)
4
+
5
+ // Eception case
6
+ if (height.length === 0) return 0;
7
8
+ let left = 0;
9
+ let right = height.length - 1;
10
+ let result = 0;
11
12
+ // Iterate to find maxiume amount of water
13
+ while (left < right) {
14
+ const amount = Math.min(height[left], height[right]) * (right - left);
15
+ result = Math.max(result, amount);
16
+ height[left] <= height[right] ? left++ : right--;
17
+ }
18
19
+ return result;
20
+};
21
22
+// TC: O(n)
23
+// SC: O(1)
0 commit comments