diff --git a/11_container_with_most_water/main.cpp b/11_container_with_most_water/main.cpp new file mode 100644 index 0000000..ac61b70 --- /dev/null +++ b/11_container_with_most_water/main.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; + +class Solution { + public: + int maxArea(vector& 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; + } +};