Skip to content

Commit 7ab34ce

Browse files
authored
Container With Most Water
Container With Most Water (Medium problem)
1 parent 55ea0cc commit 7ab34ce

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
def maxArea(self, height: List[int]) -> int:
2+
if not height:
3+
return 0
4+
5+
start, end = 0, len(height)-1
6+
answer = 0
7+
8+
while start < end:
9+
h = min(height[start], height[end])
10+
area = (end - start) * h
11+
12+
if area>answer:
13+
answer = area
14+
if h == height[start]:
15+
start+=1
16+
else:
17+
end-=1
18+
19+
return answer

0 commit comments

Comments
 (0)