11 Container With Most Water
来源:互联网 发布:淘宝意想星球 编辑:程序博客网 时间:2024/05/21 10:19
/*
* 思路:长方形面积由长乘以宽决定,当宽变小时,只能通过提高高度来获得更大的面积
* 思路:长方形面积由长乘以宽决定,当宽变小时,只能通过提高高度来获得更大的面积
*/
public class Solution {
public int maxArea(int[] height) {
if(height==null||height.length==0) return 0;
int len = height.length;
int left = 0, right = len - 1;
int max = 0;
while(left < right){
int h = Math.min(height[left], height[right]);
int w = right - left;
if(max < (h * w)){
max = h * w;
}
if(height[left] < height[right]){
++left;
}else{
--right;
}
}
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
- Container With Most Water
- Container with most water
- Container With Most Water
- Container With Most Water
- Container With Most Water
- Container With Most Water
- Container With Most Water
- Container With Most Water
- 交易流程容灾及测试策略
- 99SE常用快捷键
- C++中const、volatile、mutable、explicit的用法
- Nginx基础. Nginx数组与链表
- MySQL数据库集群进行正确配置步骤
- 11 Container With Most Water
- S3C2440 温度传感器ds18b20的驱动编写与测试
- 微博背后的那些算法
- 黑马程序员 IO流(二)
- VB6.0学习笔记 之 输入与输出(一)
- Java String.split()方法
- C#读取Excel2007的文件
- Codeforces Round #251 (Div. 2) 439B Devu, the Dumb Guy(贪心)
- 对象间的联动——观察者模式与Java事件处理(五)