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
Generated
+8
-1
@@ -1,2 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module classpath="CIDR" type="CPP_MODULE" version="4" />
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -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