diff --git a/.idea/Leet-Code-prog.iml b/.idea/Leet-Code-prog.iml index 4c94235..d6ebd48 100644 --- a/.idea/Leet-Code-prog.iml +++ b/.idea/Leet-Code-prog.iml @@ -1,2 +1,9 @@ - \ No newline at end of file + + + + + + + + \ No newline at end of file diff --git a/Medium/WaterVolume/main.cpp b/Medium/WaterVolume/main.cpp new file mode 100644 index 0000000..1d428bc --- /dev/null +++ b/Medium/WaterVolume/main.cpp @@ -0,0 +1,18 @@ +class Solution { +public: + int maxArea(vector& height) { + int left = 0; // Left Pointer + int right = height.size() - 1; // The -1 is so it's readjusted for use within Arrays + int best = 0; // Init Best value + + while (left < right) { // Mistake before (Could have easily just made sure that they're not the same values!) + int length = min(height[left], height[right]); // Find the smallest value of the two pointers + best = max(best, (length * (right - left))); // Compare old best with current best volume + if (height[right] > height[left]) { // Sliding the smallest value closer to the larger value + left++; + } else + right--; + } + return best; // Finally Returning the Value for BEST volume + } +}; \ No newline at end of file