LeetCode 之 Container With Most Water
2017-11-12 17:37
218 查看
题目链接:Container With Most Water
题意是给定n个非负整数a1, a2, a3, … ,an, 其中(i, a i)代表坐标上的一个点,过这个点向x轴作垂线,和x轴的交点为(i,0)。
需要找到两条线,其与x轴形成一个容器,使得容器包含最多的水,并返回容器的容量。
即找到ai,aj(i
题意是给定n个非负整数a1, a2, a3, … ,an, 其中(i, a i)代表坐标上的一个点,过这个点向x轴作垂线,和x轴的交点为(i,0)。
需要找到两条线,其与x轴形成一个容器,使得容器包含最多的水,并返回容器的容量。
即找到ai,aj(i
class Solution { public int maxArea(int[] height) { int l = 0, r = height.length-1; int re = 0; while(l<r){ int vec = (r-l) * Math.min(height[l], height[r]); if(vec>re) re = vec; if(height[l]<height[r]) l++; else r--; } return re; } }
相关文章推荐
- 【LEETCODE】11-Container With Most Water [Python]
- leetcode -- Container With Most Water -- 经典题目重要!
- LeetCode算法问题6 —— Container With Most Water
- leetcode:Container With Most Water 【Java】
- LeetCode Container With Most Water
- [LeetCode]Container With Most Water
- LeetCode 11 -- Container With Most Water
- 【Leetcode】Container With Most Water in JAVA
- Container With Most Water —— Leetcode
- leetcode——11——Container With Most Water
- leetcode--Container With Most Water
- 【LeetCode】Container With Most Water
- LeetCode-Container With Most Water-zz
- leetcode第11题--Container With Most Water
- [leetcode] Container With Most Water
- Leetcode之Container With Most Water 问题
- [leetcode] Container With Most Water
- LeetCode OJ Container With Most Water
- Java [leetcode 11] Container With Most Water
- leetcode--011 Container With Most Water