Skip to content

Commit 2bf7794

Browse files
authored
Merge pull request gzc426#35 from Longerhaha/master
011_(盛最多水的容器)Container With Most Water
2 parents 1283dc3 + 8eb8da7 commit 2bf7794

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
```cpp
2+
class Solution {
3+
public:
4+
//双下标一次遍历扫描
5+
int maxArea(vector<int>& height) {
6+
int height_len = height.size();
7+
int start = 0;
8+
int end = height_len - 1;
9+
int max_area = 0;
10+
while( start < end ){
11+
max_area = max(max_area, min(height[start], height[end]) * (end - start));
12+
//更新 start 和 end
13+
if(height[start] < height[end])
14+
start++;
15+
else end--;
16+
}
17+
return max_area;
18+
}
19+
};
20+
```

0 commit comments

Comments
 (0)