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 5591312 commit d71b70aCopy full SHA for d71b70a
container-with-most-water/sunjae95.js
@@ -0,0 +1,28 @@
1
+/**
2
+ * @description
3
+ * brainstorming:
4
+ * 1. brute force -> time limited
5
+ * 2. two pointer
6
+ *
7
+ * n: length of height
8
+ * time complexity: O(n)
9
+ * space complexity: O(1)
10
+ */
11
+var maxArea = function (height) {
12
+ let answer = 0;
13
+ let start = 0;
14
+ let end = height.length - 1;
15
+
16
+ while (start !== end) {
17
+ const w = end - start;
18
+ const h = Math.min(height[start], height[end]);
19
+ answer = Math.max(answer, w * h);
20
+ if (height[start] >= height[end]) {
21
+ end--;
22
+ } else if (height[start] < height[end]) {
23
+ start++;
24
+ }
25
26
27
+ return answer;
28
+};
0 commit comments