-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path11.cpp
119 lines (117 loc) · 3.15 KB
/
11.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
__________________________________________________________________________________________________
8ms
static const auto speedup = []()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
return nullptr;
}();
class Solution {
public:
int maxArea(vector<int>& height) {
int res = 0;
int left = 0, right = height.size() - 1;
while(left < right){
int h = min(height[left], height[right]);
res = max(res, h * (right - left));
// while(height[left] <= h && left < right)
// left++;
// while(height[right] <= h && left < right)
// right--;
height[left] < height[right] ? left++ : right--;
}
return res;
}
};
__________________________________________________________________________________________________
20ms
class Solution {
public:
int maxArea(vector<int>& height) {
int res = 0;
int left = 0, right = height.size() - 1;
while(left < right){
int h = min(height[left], height[right]);
res = max(res, h * (right - left));
// while(height[left] <= h && left < right)
// left++;
// while(height[right] <= h && left < right)
// right--;
height[left] < height[right] ? left++ : right--;
}
return res;
}
};
__________________________________________________________________________________________________
9644 kb
static bool _foo = ios::sync_with_stdio(false);
static ostream* _bar = cin.tie(NULL);
class Solution {
public:
int maxArea(vector<int>& height)
{
int m=0;
int i=0,j=height.size()-1;
while(i<j)
{
m = max(m,min(height[i],height[j])*(j-i));
height[i]<height[j]?i++:j--;
}
return m;
}
};
__________________________________________________________________________________________________
9688 kb
static int pre = []() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
return 0;
}();
class Solution {
public:
int maxArea(vector<int>& height) {
auto area = 0;
auto front = 0;
auto end = static_cast<int>(height.size() - 1);
while (front < end) {
auto length = end - front;
auto heightA = height[front];
auto heightB = height[end];
auto minHeight = 0;
if (heightA > heightB) {
minHeight = heightB;
end--;
}
else {
minHeight = heightA;
front++;
}
auto tempArea = minHeight * length;
if (tempArea > area)
area = tempArea;
}
return area;
}
};
__________________________________________________________________________________________________
9764 kb
static int x = [](){
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
return NULL;
}();
class Solution {
public:
int maxArea(vector<int>& height) {
int l = height.size();
int res = 0;
for(int i = 0; i<l; i++){
for(int j = i+1; j<l; j++){
res = max(res, min(height[i],height[j])*(j-i));
}
}
return res;
}
};
__________________________________________________________________________________________________