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 18150be commit 21b5059Copy full SHA for 21b5059
container-with-most-water/gitsunmin.ts
@@ -0,0 +1,15 @@
1
+/**
2
+ * https://leetcode.com/problems/container-with-most-water/
3
+ * time complexity : O(n)
4
+ * space complexity : O(1)
5
+ */
6
+export function maxArea(height: number[]): number {
7
+ let s = 0, e = height.length - 1, max = 0;
8
+
9
+ while (s < e) {
10
+ max = Math.max((e - s) * Math.min(height[s], height[e]), max);
11
+ if (height[s] < height[e]) s++;
12
+ else e--;
13
+ }
14
+ return max;
15
+};
0 commit comments