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 e994de4 commit 2e484d9Copy full SHA for 2e484d9
container-with-most-water/lhc0506.js
@@ -0,0 +1,32 @@
1
+/**
2
+ * @param {number[]} height
3
+ * @return {number}
4
+ */
5
+var maxArea = function(height) {
6
+ let result = 0;
7
+ let left = 0;
8
+ let right = height.length - 1;
9
+
10
+ while(left < right) {
11
+ const leftHeight = height[left];
12
+ const rightHeight = height[right];
13
+ const width = right - left;
14
15
+ const minHeight = leftHeight < rightHeight ? leftHeight : rightHeight;
16
+ const area = minHeight * width;
17
18
+ if (area > result) {
19
+ result = area;
20
+ }
21
22
+ if (leftHeight <= rightHeight) {
23
+ left++;
24
+ } else {
25
+ right--;
26
27
28
+ return result;
29
+};
30
31
+// 시간 복잡도: O(n)
32
+// 공간 복잡도: O(1)
0 commit comments