티스토리 뷰

Algorithm

Container With Most Water Javascript

Kyeongti 2022. 10. 5. 10:55
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;
};
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/09   »
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
글 보관함