-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path0011.cpp
51 lines (42 loc) · 976 Bytes
/
0011.cpp
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
47
48
49
50
51
//Solution 1 :-
class Solution {
public:
int maxArea(vector<int> &arr) {
int i = 0, j = int(arr.size()) - 1;
int ans = 0;
while (i < j) {
int curr = min(arr[i], arr[j]) * (j - i);
ans = max(curr, ans);
if (arr[i] <= arr[j])
i++;
else if (arr[j] <= arr[i])
j--;
else
break;
}
return ans;
}
};
//Solution 2 :-
class Solution {
public:
int maxArea(vector<int>& height) {
int l = 0;
int r = height.size() - 1;
int area = 0;
while(l < r){
int temp = 0;
if(height[l] <= height[r]){
temp = height[l] * (r - l);
l++;
}
else{
temp = height[r] * (r - l);
r--;
}
if(temp > area)
area = temp;
}
return area;
}
};