티스토리 뷰
var maxArea = function(height) {
let leftIndex = 0;
let rightIndex = height.length - 1;
let result = 0;
while (leftIndex < rightIndex) {
if (height[leftIndex] < height[rightIndex]) {
result = Math.max(height[leftIndex] * (rightIndex - leftIndex), result);
leftIndex += 1;
} else {
result = Math.max(height[rightIndex] * (rightIndex - leftIndex), result);
rightIndex -= 1;
}
}
return result;
};
'Algorithm' 카테고리의 다른 글
22. Generate Parentheses JavaScript (0) | 2022.10.14 |
---|---|
19. Remove Nth Node From End of List JavaScript (0) | 2022.10.12 |
1221. Split a String in Balanced Strings In JavaScript [탐욕법] (0) | 2021.12.28 |
BFS 넓이우선탐색 - JavaScript (0) | 2021.12.23 |
LeetCode - 653. Two Sum IV - Input is a BST in Javascript (0) | 2021.11.26 |
댓글