Files
2026-08-04 17:39:14 +01:00

18 lines
1.0 KiB
C++

class Solution {
public:
int maxArea(vector<int>& 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
}
};