那种记忆床垫好不好?# Living
l*i
1 楼
Given n non-negative integers a1, a2, ..., an, where each represents a point
at coordinate (i, ai). n vertical lines are drawn such that the two
endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together
with x-axis forms a container, such that the container contains the most
water.
Anyone explain the testcase [1,2,4,3], it seems to me that the answer is 6
for this case.
the bar between h=1 and h=2 can trap 1*1 = 1 unit of water
the bar between h=2 and h=4 can trap 2*1 = 2 unit of water
the bar between h=4 and h=3 can trap 3*1 = 3 unit of water
add up to 1 + 2 + 3 = 6.
Did I miss something?
at coordinate (i, ai). n vertical lines are drawn such that the two
endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together
with x-axis forms a container, such that the container contains the most
water.
Anyone explain the testcase [1,2,4,3], it seems to me that the answer is 6
for this case.
the bar between h=1 and h=2 can trap 1*1 = 1 unit of water
the bar between h=2 and h=4 can trap 2*1 = 2 unit of water
the bar between h=4 and h=3 can trap 3*1 = 3 unit of water
add up to 1 + 2 + 3 = 6.
Did I miss something?