Container with most water

来源:互联网 发布:数据有效性怎么设置 编辑:程序博客网 时间:2024/05/17 06:26

题目比较简单,每次找较小的板往里移,得到的容器的容积最大的就是所求的容积

public class Solution {    public static int maxArea(int[] height) {        int begin = 0, high, end = height.length - 1;        int max = 0;        while (end >= begin) {            high = height[begin] < height[end] ? height[begin] : height[end];            max = high * (end - begin) > max ? high * (end - begin) : max;            if (height[begin] < height[end])                begin++;            else                end--;        }        return max;    }}


0 0
原创粉丝点击