We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 04aab79 commit 7c69408Copy full SHA for 7c69408
container-with-most-water/printjin-gmailcom.py
@@ -1,13 +1,13 @@
1
class Solution:
2
def maxArea(self, height):
3
- def divide_and_conquer(left, right):
4
- if left >= right:
5
- return 0
6
- min_height = min(height[left], height[right])
7
- area = min_height * (right - left)
8
- return max(
9
- area,
10
- divide_and_conquer(left + 1, right),
11
- divide_and_conquer(left, right - 1)
12
- )
13
- return divide_and_conquer(0, len(height) - 1)
+ left, right = 0, len(height) - 1
+ max_area = 0
+ while left < right:
+ h = min(height[left], height[right])
+ w = right - left
+ max_area = max(max_area, h * w)
+ if height[left] < height[right]:
+ left += 1
+ else:
+ right -= 1
+ return max_area
0 commit comments