-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSolution.java
More file actions
10 lines (9 loc) · 907 Bytes
/
Copy pathSolution.java
File metadata and controls
10 lines (9 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
public class Solution
{ // Two pointers solution public int maxArea(int[] height) { int maxArea = 0; if (height ==
// null || height.length == 0) return maxArea; int i = 0; int j = height.length - 1;
// while (i < j) { maxArea = Math.max(maxArea, Math.min(height[j], height[i]) * (j - i));
// if (height[i] > height[j]) j--; else i++; } return maxArea;
// } // Brute force Solution public int maxArea(int[] height) { int maxArea = 0; if (height ==
// null || height.length == 0) return maxArea; for (int i = 0; i < height.length; i++) {
// for (int j = 1; j < height.length; j++) { maxArea = Math.max(maxArea, Math.min
// (height[j], height[i]) * (j - i)); } } return maxArea; }}