您的位置:首页 > 大数据 > 人工智能

*LeetCode-Container With Most Water

2015-09-19 10:53 495 查看
读题就读了很久 

解法很巧妙 两个指针在两端 向中心挪动 因为只要其中一个高 它下次就不用挪 挪另一个 因为挪了没有意义 过程中keep max area

public class Solution {
public int maxArea(int[] height) {
int i = 0;
int j = height.length - 1;
int area = 0;
while ( i < j ){
area = Math.max( area, Math.min(height[i], height[j]) * (j-i) );
if ( height[i] > height[j] )
j --;
else
i ++;
}
return area;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: