We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 583ff1e commit d2b5c4eCopy full SHA for d2b5c4e
container-with-most-water/robinyoon-dev.js
@@ -0,0 +1,32 @@
1
+/**
2
+ * @param {number[]} height
3
+ * @return {number}
4
+ */
5
+var maxArea = function (height) {
6
+
7
+ // 투 포인터
8
+ // 왼쪽 포인터, 오른쪽 포인터. lower 라인의 포인터를 움직여야함.
9
10
+ let leftPointer = 0;
11
+ let rightPointer = height.length - 1;
12
+ let tempMax = 0;
13
14
+ while (leftPointer !== rightPointer) {
15
+ let areaHeight = Math.min(height[leftPointer], height[rightPointer]);
16
17
+ let areaWidth = rightPointer - leftPointer;
18
19
+ let waterArea = areaHeight * areaWidth;
20
21
+ tempMax = Math.max(tempMax, waterArea);
22
23
+ if (height[leftPointer] < height[rightPointer]) {
24
+ leftPointer++;
25
+ } else {
26
+ rightPointer--;
27
+ }
28
29
30
+ return tempMax;
31
32
+};
0 commit comments