mirror of
https://github.com/mudabbir-ahmad/Leet-Code-prog.git
synced 2026-10-07 18:30:20 +00:00
new leet code Q solved
This commit is contained in:
1 parent
5d2c2664cc
commit
3cd454359e
2 files changed
+26
-1
No files matched your search
@@ -0,0 +1,18 @@
|
||||
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
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user