Compare commits
No commits in common. "8dc2f5e9a5bcd239005cbac212ae4d019ce550f1" and "1610db5ede7db313780ad65c4aae197e990cfa41" have entirely different histories.
8dc2f5e9a5
...
1610db5ede
33
maxArea.cpp
33
maxArea.cpp
@ -1,33 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
class Solution
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
int maxArea(vector<int> &height)
|
|
||||||
{
|
|
||||||
int maxArea = 0;
|
|
||||||
int left = 0;
|
|
||||||
int right = height.size() - 1;
|
|
||||||
while (left < right){
|
|
||||||
maxArea = max(maxArea,(right - left)*min(height[right] , height[left]));
|
|
||||||
if( height[left] < height[right]){
|
|
||||||
left++;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
right--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return maxArea;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
vector<int> height = {1, 8, 6, 2, 5, 4, 8, 3, 7};
|
|
||||||
Solution s;
|
|
||||||
cout << s.maxArea(height);
|
|
||||||
return 0;
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user