class Solution {
    public static int maxArea(int[] height) {
		int left = 0;
		int right = height.length - 1;
		int max = calcArea(left, right, height);

		while (left != right) {
			if (height[left] < height[right]) {
				left++;
			} else {
				right--;
			}

			max = Math.max(max, calcArea(left, right, height));
		}
		return max;
	}

	public static int calcArea(int left, int right, int[] height) {
		return (right - left) * Math.min(height[left], height[right]);
	}
}

 

'알고리즘 공부 > leetcode' 카테고리의 다른 글

leetcode: Trapping Rain Water  (0) 2020.12.27
leetcode: Median of two sorted Arrays  (0) 2020.12.26
leetcode: Letter Combinations of a Phone number  (0) 2020.12.26
leetcode: Palindrome Partitioning  (0) 2020.12.26
leetcode: 4sum  (0) 2020.12.17

+ Recent posts