-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Manipulates "pointer" values cleverly in order to find a pair of pillars with the highest volume possible
- Loading branch information
1 parent
ebbd5e2
commit 70c8aee
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class Solution(object): | ||
def maxArea(self, height): | ||
""" | ||
:type height: List[int] | ||
:rtype: int | ||
""" | ||
rpointer = len(height) - 1 | ||
maximum = 0 | ||
lpointer = 0 | ||
lhighest = 0 | ||
rhighest = 0 | ||
area = 0 | ||
while rpointer > lpointer: | ||
if height[lpointer] > lhighest or height[rpointer] > rhighest: | ||
area = min(height[lpointer], height[rpointer]) * abs(lpointer-rpointer) | ||
if area > maximum: | ||
maximum = area | ||
if height[lpointer] > lhighest: | ||
lhighest = height[lpointer] | ||
if height[rpointer] > rhighest: | ||
rhighest = height[rpointer] | ||
if height[lpointer] > height[rpointer]: | ||
rpointer -= 1 | ||
elif height[lpointer] < height[rpointer]: | ||
lpointer += 1 | ||
else: | ||
lpointer += 1 | ||
rpointer -= 1 | ||
return maximum | ||
|
||
|