Skip to content

Commit 8674180

Browse files
committed
3
1 parent 7412a13 commit 8674180

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public:
3+
int maxArea(vector<int>& height) {
4+
// Start typing your C/C++ solution below
5+
// DO NOT write int main() function
6+
if (height.size() < 2)
7+
return 0;
8+
int left = 0;
9+
int right = height.size() - 1;
10+
int maxarea = 0;
11+
while (left < right) {
12+
maxarea = max(maxarea, min(height[left], height[right]) * (right - left));
13+
if (height[left] < height[right])
14+
left += 1;
15+
else
16+
right -= 1;
17+
}
18+
return maxarea;
19+
}
20+
};

0 commit comments

Comments
 (0)