feat: 11_container_with_most_water
This commit is contained in:
parent
3940f5826e
commit
acb6fd184e
21
11_container_with_most_water/main.cpp
Normal file
21
11_container_with_most_water/main.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int maxArea(vector<int>& heights) {
|
||||
int result = 0;
|
||||
int l = 0, r = heights.size() - 1;
|
||||
|
||||
while (l != r) {
|
||||
result = max(result, (r - l) * min(heights[l], heights[r]));
|
||||
if (heights[l] <= heights[r]) {
|
||||
l++;
|
||||
} else {
|
||||
r--;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user