From 873ea04f40d8eb11868edc48af615adc60b5b758 Mon Sep 17 00:00:00 2001 From: ashwek Date: Thu, 13 Dec 2018 13:51:10 +0530 Subject: [PATCH] Solution.cpp - 0011 --- .../Solution.cpp | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 solution/0011.Container With Most Water/Solution.cpp diff --git a/solution/0011.Container With Most Water/Solution.cpp b/solution/0011.Container With Most Water/Solution.cpp new file mode 100644 index 0000000000000..50d2b7b750cd4 --- /dev/null +++ b/solution/0011.Container With Most Water/Solution.cpp @@ -0,0 +1,20 @@ +class Solution { +public: + int maxArea(vector& height) { + int Max = -1, Min, area; + int s = 0, e = height.size()-1; + + while( s < e ){ + if( height[s] < height[e] ){ + area = (e-s) * height[s]; + s++; + } + else{ + area = (e-s) * height[e]; + e--; + } + if( area > Max ) Max = area; + } + return Max; + } +};