forked from changqing16/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11.cpp
More file actions
30 lines (29 loc) · 687 Bytes
/
11.cpp
File metadata and controls
30 lines (29 loc) · 687 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;
int maxArea(vector<int> &height)
{
int max = 0, tmp, ans = 0, cur, max2;
int size = height.size();
for (int i = 0; i < size; i++)
{
if (max < height[i])
max = height[i];
else
continue;
max2 = 0;
for (int j = size - 1; j > i; j--)
{
if (max2 < height[j])
max2 = height[j];
else
continue;
tmp = height[i] < height[j] ? height[i] : height[j];
cur = tmp * (j - i);
if (cur > ans)
ans = cur;
}
}
return ans;
}