aboutsummaryrefslogtreecommitdiff
path: root/other/most_water.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'other/most_water.cpp')
-rw-r--r--other/most_water.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/other/most_water.cpp b/other/most_water.cpp
new file mode 100644
index 0000000..89d4e19
--- /dev/null
+++ b/other/most_water.cpp
@@ -0,0 +1,21 @@
+#include <bits/stdc++.h>
+using namespace std;
+
+class Solution {
+public:
+ int maxArea(vector<int> &height) {
+ int start = 0, max = 0, end = height.size() - 1;
+ while (start < end) {
+ int x = end - start;
+ int y = height[start] > height[end] ? height[end] : height[start];
+ max = (x * y) > max ? (x * y) : max;
+ if (height[start] > height[end])
+ end--;
+ else
+ start++;
+ }
+ return max;
+ }
+};
+
+int main() {}