Skip to content

Commit ccda249

Browse files
committed
Time: 4 ms (84.97%), Space: 55.8 MB (28.39%) - LeetHub
1 parent 31ff977 commit ccda249

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution {
2+
public int maxArea(int[] height) {
3+
4+
int maxArea = Integer.MIN_VALUE;
5+
int left=0;
6+
int right=height.length-1;
7+
8+
9+
while(left < right)
10+
{
11+
int shorterLine = Math.min(height[left],height[right]);
12+
maxArea = Math.max(maxArea,shorterLine*(right-left));
13+
14+
if(height[left] < height[right])
15+
{
16+
left++;
17+
}
18+
else
19+
{
20+
right--;
21+
}
22+
}
23+
24+
return maxArea;
25+
26+
}
27+
}

0 commit comments

Comments
 (0)