Skip to content

Commit bf05e92

Browse files
committed
solve container-with-most-water
1 parent 3e99718 commit bf05e92

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# TC : O(n)
2+
# SC : O(1)
3+
class Solution:
4+
def maxArea(self, height: List[int]) -> int:
5+
low = 0
6+
high = len(height) - 1
7+
max_val = 0
8+
9+
while low < high:
10+
val = min(height[low], height[high]) * (high - low)
11+
max_val = max(val, max_val)
12+
if height[low] < height[high]:
13+
low += 1
14+
elif height[low] > height[high]:
15+
high -= 1
16+
# increment low or decrement high
17+
else:
18+
low += 1
19+
20+
return max_val

0 commit comments

Comments
 (0)