Leetcode-Container With Most Water
2014-11-28 04:44
363 查看
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.
Note: You may not slant the container.
Analysis:
Solution:
Note: You may not slant the container.
Analysis:
Solution:
public class Solution { public int maxArea(int[] height) { int max = 0; int head = 0; int end = height.length-1; while (head<end){ int left = height[head]; int right = height[end]; int vol = (end-head)*Math.min(left,right); if (vol>max) max = vol; if (left<=right) while (head<end && left>=height[head]) head++; else while (head< end && right>=height[end]) end--; } return max; } }
相关文章推荐
- 【LeetCode】Container With Most Water 解题报告
- leetcode—Container With Most Water
- leetcode之11. Container With Most Water(C++解法)
- LeetCode-Container With Most Water
- [LeetCode] Container With Most Water
- LeetCode 11 Container With Most Water(最大水容器)
- leetcode——Container With Most Water
- leetcode-Container With Most Water
- Leetcode 11 Container With Most Water
- LeetCode 11 Container With Most Water (C,C++,Java,Python)
- LeetCode 11 -- Container With Most Water
- leetcode-java.T011_ContainerWithMostWater 找两条竖线然后这两条线以及X轴构成的容器能容纳最多的水
- [LeetCode] Container With Most Water, Solution
- LeetCode Container With Most Water
- Container With Most Water —— Leetcode
- [LeetCode] Container With Most Water 简要分析
- [LeetCode-Algorithms-11] "Container With Most Water" (2017.10.2-WEEK5)
- leetcode - Container With Most Water
- LeetCode Container With Most Water
- LeetCode Container With Most Water