From acb6fd184e8d7260864006a86c35b15f151d5c22 Mon Sep 17 00:00:00 2001 From: SquidSpirit Date: Tue, 18 Feb 2025 23:36:26 +0800 Subject: [PATCH] feat: 11_container_with_most_water --- 11_container_with_most_water/main.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 11_container_with_most_water/main.cpp 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; + } +};