-
-
Notifications
You must be signed in to change notification settings - Fork 335
Expand file tree
/
Copy pathrobinyoon-dev.js
More file actions
32 lines (23 loc) · 738 Bytes
/
robinyoon-dev.js
File metadata and controls
32 lines (23 loc) · 738 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* @param {number[]} height
* @return {number}
*/
var maxArea = function (height) {
// 투 포인터
// 왼쪽 포인터, 오른쪽 포인터. lower 라인의 포인터를 움직여야함.
let leftPointer = 0;
let rightPointer = height.length - 1;
let tempMax = 0;
while (leftPointer !== rightPointer) {
let areaHeight = Math.min(height[leftPointer], height[rightPointer]);
let areaWidth = rightPointer - leftPointer;
let waterArea = areaHeight * areaWidth;
tempMax = Math.max(tempMax, waterArea);
if (height[leftPointer] < height[rightPointer]) {
leftPointer++;
} else {
rightPointer--;
}
}
return tempMax;
};