-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontainer_With_Most_Water.py
More file actions
34 lines (30 loc) · 952 Bytes
/
container_With_Most_Water.py
File metadata and controls
34 lines (30 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Solution:
def maxArea(self, height):
res = 0
left_p_indx = 0
right_p_indx = len(height) - 1
loop_trun = True
while loop_trun:
left_p = height[left_p_indx]
right_p = height[right_p_indx]
area = (right_p_indx - left_p_indx) * min(left_p, right_p)
res = max(area,res)
if right_p_indx==left_p_indx:
loop_trun = False
elif left_p>right_p:
right_p_indx-=1
else:
left_p_indx+=1
return res
# Brute force
# p = 0
# for i in range(len(height)):
# for j in range(i+1, len(height)):
# area = (j-i)*min(height[i], height[j])
# p = max(p, area)
# return p
if __name__ == '__main__':
heigth = [1, 8, 6, 2, 5, 4, 8, 3, 7]
sol = Solution()
result = sol.maxArea(heigth)
print(result)