-
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.
added container with most water question
- Loading branch information
Showing
2 changed files
with
28 additions
and
1 deletion.
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,27 @@ | ||
'''11. Container With Most Water | ||
Medium | ||
You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]). | ||
Find two lines that together with the x-axis form a container, such that the container contains the most water. | ||
Return the maximum amount of water a container can store. | ||
Notice that you may not slant the container.''' | ||
|
||
class Solution: | ||
def maxArea(self, height): | ||
|
||
maxValue = 0 | ||
left = 0 | ||
right = len(height) - 1 | ||
|
||
while left < right: | ||
currentArea = min(height[left], height[right]) * (right - left) | ||
maxValue = max(maxValue, currentArea) | ||
|
||
if height[left] < height[right]: | ||
left += 1 | ||
else: | ||
right -= 1 | ||
|
||
return maxValue |
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