11. 盛最多水的容器

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

代码:

class Solution {
    public int maxArea(int[] height) {
        int len = height.length;
        int area = 0;
        int max = 0;
        for (int i = 0; i < len-1; i++) {
            for (int j = i + 1; j < len; j++) {
                area = (j - i) * Math.min(height[i], height[j]);
                max = Math.max(max, area);
            }
        }
        return max;
    }
}

思路:题目意思就是求最大面积的问题。直接使用暴力求解法,将所有面积都求出来,取最大值。


觉得内容还不错?打赏个钢镚鼓励鼓励!!👍