Skip to content

Commit 04aab79

Browse files
Solve : Container With Most Water
1 parent 1f36003 commit 04aab79

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
class Solution:
22
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
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)

0 commit comments

Comments
 (0)