11. Container With Most Water
来源:互联网 发布:传奇盛世心法7升八数据 编辑:程序博客网 时间:2024/06/06 18:35
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.
木桶盛水问题,比较最左侧和最右侧的高度,哪边小就把哪边往中间移动。如左侧是6 右侧是8 ,间距为10,此时盛水6*10;6是制约侧,如果10向中间移动水桶的有效高度不会超过6而宽度减小盛水减少,所以将6向右移动有可能出现更大值
public class Solution { public int maxArea(int[] height) { if(height.length<=1||height==null) return 0; int l=0;int r=height.length-1; int max=0; while(l<=r){ max=Math.max(max,Math.min(height[l],height[r])*(r-l)); if(height[l]<=height[r]) l++; else r--; } return max; }}
0 0
- 11.Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11.Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 博客更新的通知
- 西安十五日游day10 分治
- 哈夫曼编码
- JQ的index()
- FFMPEG学习----遍历所支持的封装格式
- 11. Container With Most Water
- 简单笔记的演示
- JQuery中attr()获取和设置元素属性
- 二分之——查字典
- Python- 队列
- Android入门基础知识
- Qt 程序打包发布总结
- hdu 4028 The time of a day(离散化dp)
- go-map