Skip to content

Commit 7c69408

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

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
class Solution:
22
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)
3+
left, right = 0, len(height) - 1
4+
max_area = 0
5+
while left < right:
6+
h = min(height[left], height[right])
7+
w = right - left
8+
max_area = max(max_area, h * w)
9+
if height[left] < height[right]:
10+
left += 1
11+
else:
12+
right -= 1
13+
return max_area

0 commit comments

Comments
 (0)