水桶装水问题
来源:互联网 发布:windows微信登录 编辑:程序博客网 时间:2024/04/30 03:54
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.
想了很长时间,实际上处理的长方形的面积。假设横坐标长度为 x, 纵坐标长度为 y(取数组两端的最小值 ),求一个面积最大的长方形。
s = x*y
调整x和y值 达到 s最大。
class Solution {public: int maxArea(vector<int>& height) { int l =0; int h = height.size(); int vol =0; h--; int max=0; while(l<h) { int min = height[l]>height[h]?height[h]:height[l]; vol = min*(h-l); if(vol>max) max = vol; if(height[l]<height[h]) l++; else h--; } return max; }};
0 0
- 水桶装水问题
- Container With Most Water-水桶装水问题
- 水桶问题
- 练练大脑3:水桶问题
- 三个水桶等分水问题
- 三只水桶等分水问题
- 三只水桶等分水问题
- 三种水桶,等分为两半问题
- 一个挑剔的吃货(水桶问题)
- 【面试题】:两水桶倒水问题
- 算法系列之二:三只水桶等分水问题
- 算法系列之二:三只水桶等分水问题
- 算法系列之二:三只水桶等分水问题
- 算法系列之二: 三只水桶等分水问题
- 算法系列之二: 三只水桶等分水问题
- 算法乐趣--三只水桶等分水问题
- 算法之三只水桶等分水问题
- 对于"容量分别为A与B的两个水桶,是否能够通过互相倒水可以得到1~MAX(A,B)所有容量的水"问题的分析
- gulp压缩js应用示例
- Ubuntu 16.04 + Matlab 2014a + caffe 配置
- 修改tomcat的内存
- 穿回南宋第N+1张 力战玄天
- The DAO的漏洞利用分析
- 水桶装水问题
- js面试总结
- 程序员不可忽视的事——使用电脑注意事项
- UVA 10137 The Trip
- LNMP1.3+WordPress 无法删除插件和更新WordPress 目录权限问题初探
- linux用VI编辑后保存退出命令
- 匹配正则
- 51NOD 1475 建设国家
- MVP