Loading

11. 盛最多水的容器

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

使用双指针

class Solution {
    public int maxArea(int[] height) {
        int i = 0, j = height.length - 1, res = 0;
        while(i < j){
            res = height[i] < height[j] ? 
            Math.max(res, (j - i) * height[i++]) :
            Math.max(res, (j - i) * height[j --]);
        } 
        return res;
    }
}
posted @ 2021-11-14 13:06  Zhbeii  阅读(27)  评论(0编辑  收藏  举报