Skip to content

Commit 424ff67

Browse files
Add files via upload
1 parent 60e692c commit 424ff67

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
2+
3+
def mostWater(array):
4+
max_score = 0
5+
for i in range(len(array)):
6+
#cu_num = i
7+
for j in range(i + 1, len(array)):
8+
#p_num = j
9+
height = min(array[i], array[j])
10+
width = j - i
11+
area = height * width
12+
max_score = max(max_score, area)
13+
#if(max_score < area):
14+
#max_score = area
15+
return max_score
16+
17+
18+
19+
array = [7, 1, 2, 3, 9]
20+
print(mostWater(array))
21+
22+
array = [1, 8, 6, 2, 5, 4, 8, 3, 7]
23+
print(mostWater(array))
24+
25+
26+
27+
28+
29+
water = [3, 0, 0, 2, 0, 4]
30+
print(mostWater(water))
31+
32+
33+
34+
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+
def mostWater(array):
47+
max_score = 0
48+
p1 = 0
49+
p2 = len(array)-1
50+
while(p1 < p2):
51+
for i in range(len(array)):
52+
area = min(array[p1], array[p2]) * (p2 -p1)
53+
max_score = max(max_score, area)
54+
if(array[p1] < array[p2]):
55+
p1 += 1
56+
else:
57+
p2 -= 1
58+
return max_score
59+
60+
61+
62+
63+
array = [1, 8, 6, 2, 5, 4, 8, 3, 7]
64+
print(mostWater(array))
65+
66+
67+
array = [7, 1, 2, 3, 9]
68+
print(mostWater(array))
69+
70+
71+
array = [1,8,100,2,100,4,8,3,7]
72+
print(mostWater(array))
73+
74+
75+
water = [3, 0, 0, 2, 0, 4]
76+
print(mostWater(water))
77+
78+
79+
80+
81+

0 commit comments

Comments
 (0)