[LeetCode]11. Container With Most Water

来源:互联网 发布:硕放菜鸟网络招聘 编辑:程序博客网 时间:2024/05/30 19:33

https://leetcode.com/problems/container-with-most-water/

很简单,要读题,就是找两个竖线与横轴包围的最大面积,和trap water不一样。



public class Solution {    public int maxArea(int[] nums) {        int beg = 0;        int end = nums.length - 1;        int res = 0;        while (beg < end) {            res = Math.max(res, (end - beg) * Math.min(nums[end], nums[beg]));            if (nums[beg] < nums[end]) {                beg++;            } else {                end--;            }        }        return res;    }}


0 0
原创粉丝点击