-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathsolution011.cpp
More file actions
46 lines (41 loc) · 749 Bytes
/
solution011.cpp
File metadata and controls
46 lines (41 loc) · 749 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* @file Container With Most Water
* Two pointer.
*
* cpselvis ([email protected])
* August 4, 2016
*/
#include<cstdio>
#include<vector>
using namespace std;
class Solution {
public:
int maxArea(vector<int>& height) {
int max = 0, size = height.size(), area, distance, h, min;
int i = 0, j = size - 1;
while (i < j)
{
distance = j - i;
if (height[i] < height[j])
{
min = height[i];
i ++;
}
else
{
min = height[j];
j --;
}
area = distance = distance * min;
max = area > max ? area : max;
}
return max;
}
};
int main(int argc, char **argv)
{
Solution s;
int arr[] = {1, 1};
vector<int> v(arr + 0, arr + 2);
printf("%d\n", s.maxArea(v));
}