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 7acd8f7 commit 389f3ceCopy full SHA for 389f3ce
container-with-most-water/jdy8739.js
@@ -0,0 +1,32 @@
1
+/**
2
+ * @param {number[]} height
3
+ * @return {number}
4
+ */
5
+var maxArea = function(height) {
6
+ let max = 0;
7
+
8
+ let startIdx = 0;
9
+ let endIdx = height.length - 1;
10
11
+ while (startIdx < endIdx) {
12
+ const start = height[startIdx];
13
+ const end = height[endIdx];
14
15
+ const gap = endIdx - startIdx;
16
+ const min = Math.min(start, end);
17
18
+ const area = gap * min;
19
20
+ max = Math.max(max, area);
21
22
+ if (start < end) startIdx++;
23
+ else endIdx--;
24
+ }
25
26
+ return max;
27
+};
28
29
+// 시간복잡도 O(n)
30
+// n은 주어진 배열(height)의 길이
31
32
0 commit comments