由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - leetcode container with most water
相关主题
leetcode一道题leetcode的candy这样的题
leetcode的container with most water题Modified Maximal Rectangle problem from Leetcode
也发个A家电面经leetcode: largest rectangle in histogram求帮助
求OJ container with most water O(n)解法Question about Leetcode: Maximum rectangle
DP算法占用的空间leetcode一题
发觉最近流行这些X坐标扫描的题Leetcode上subsets-ii的疑问
Largest Rectangle in Histogram关于leetcode: Container With Most Water这道题
借人气,问道题请教大家一道Google的题目
相关话题的讨论汇总
话题: container话题: water话题: bar话题: trap话题: most
进入JobHunting版参与讨论
1 (共1页)
l***i
发帖数: 1309
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?
b****e
发帖数: 45
2
You can use only one container here: the one defined by the left-most bar
and the right-most bar that you choose to form the container. You used
multiple containers in your calculation.

point
together

【在 l***i 的大作中提到】
: 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

l***i
发帖数: 1309
3
Thanks, that explains it.
c****9
发帖数: 164
4
话说Largest Rectangle in Histogram这道题除去stack的o(n)方法,可否用这道题
的两边夹做呢?
c****9
发帖数: 164
5
仔细想了下,不能。。因为需要考虑内部的情况

【在 c****9 的大作中提到】
: 话说Largest Rectangle in Histogram这道题除去stack的o(n)方法,可否用这道题
: 的两边夹做呢?

1 (共1页)
进入JobHunting版参与讨论
相关主题
请教大家一道Google的题目DP算法占用的空间
请问一道面试题发觉最近流行这些X坐标扫描的题
请教一个Axis-Aligned Rectangles的算法Largest Rectangle in Histogram
求overlap的rectagales借人气,问道题
leetcode一道题leetcode的candy这样的题
leetcode的container with most water题Modified Maximal Rectangle problem from Leetcode
也发个A家电面经leetcode: largest rectangle in histogram求帮助
求OJ container with most water O(n)解法Question about Leetcode: Maximum rectangle
相关话题的讨论汇总
话题: container话题: water话题: bar话题: trap话题: most