Skip to content

Commit 19ae39a

Browse files
authored
Merge pull request gzc426#4 from Syuan-Cheng/Syuan-Cheng-patch-3
Create syuan.md
2 parents 0786c22 + 8030628 commit 19ae39a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

2018.11.26-leetcode11/syuan.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
##### 题目
2+
3+
```
4+
给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) 。在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0)。找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水。
5+
6+
说明:你不能倾斜容器,且 n 的值至少为 2。
7+
```
8+
![微信截图_20181127122321](2DF0C29B574D4A30BFAB06ABDF185FA9)
9+
```
10+
图中垂直线代表输入数组 [1,8,6,2,5,4,8,3,7]。在此情况下,容器能够容纳水(表示为蓝色部分)的最大值为 49。
11+
示例:
12+
13+
输入: [1,8,6,2,5,4,8,3,7]
14+
输出: 49
15+
```
16+
##### 思路
17+
双指针
18+
19+
##### 代码
20+
21+
```
22+
class Solution {
23+
public int maxArea(int[] height){
24+
int maxarea=0;
25+
int i=0;
26+
int j=height.length-1;
27+
28+
while(i<j){
29+
maxarea=Math.max(maxarea,Math.min(height[i],height[j])*(j-i));
30+
if(height[i]<height[j]){
31+
i++;
32+
}else{
33+
j--;
34+
}
35+
}
36+
return maxarea;
37+
}
38+
}
39+
```

0 commit comments

Comments
 (0)