Skip to content

Commit b179bce

Browse files
authored
Create Felix.md
1 parent c31303b commit b179bce

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

2019.11.25-leetcode80/Felix.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
```javascript
2+
package leetcode.medium;
3+
/**
4+
* @author Felix
5+
* @date 2018年10月31日下午9:59:27
6+
@version 给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) 。在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为
7+
(i, ai) 和 (i, 0)。找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水。说明:你不能倾斜容器,且 n 的值至少为 2。
8+
*/
9+
public class MaxArea {
10+
public int maxArea(int[] height){
11+
int len = height.length;
12+
int max = 0,low = 0,high = len - 1;
13+
while(low < high){
14+
int lowMax = height[low],highMax = height[high];
15+
int water = (high - low) * (lowMax < highMax ? lowMax : highMax);
16+
max = water > max ? water : max;
17+
18+
if(height[low] <= height[high]){
19+
while(low < high && height[low] <= lowMax)
20+
low++;
21+
}else{
22+
while(high > low && height[high] <= highMax)
23+
high--;
24+
}
25+
}
26+
27+
return max;
28+
}
29+
}
30+
```

0 commit comments

Comments
 (0)