-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path011.rb
More file actions
34 lines (28 loc) · 639 Bytes
/
Copy path011.rb
File metadata and controls
34 lines (28 loc) · 639 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
# @param {Integer[]} height
# @return {Integer}
def get_volumn(height, i, j)
length = j - i
if height[i] < height[j]
length * height[i]
else
length * height[j]
end
end
def max_area(height)
i = 0
j = height.length - 1
max_volumn = get_volumn(height, i, j)
while i < j do
if height[i] < height[j]
i_height = height[i]
i += 1 while height[i] <= i_height && i < j
else
j_height = height[j]
j -= 1 while height[j] <= j_height && i < j
end
break if i >= j
new_volumn = get_volumn(height, i, j)
max_volumn = new_volumn if new_volumn > max_volumn
end
max_volumn
end