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 1f36003 commit 04aab79Copy full SHA for 04aab79
container-with-most-water/printjin-gmailcom.py
@@ -1,8 +1,13 @@
1
class Solution:
2
def maxArea(self, height):
3
- max_area = 0
4
- for i in range(len(height)):
5
- for j in range(i + 1, len(height)):
6
- area = (j - i) * min(height[i], height[j])
7
- max_area = max(max_area, area)
8
- return max_area
+ def divide_and_conquer(left, right):
+ if left >= right:
+ return 0
+ min_height = min(height[left], height[right])
+ area = min_height * (right - left)
+ 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)
0 commit comments