Leetcode Array 11 Container With Most Water

Posted 梦_星_空

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode Array 11 Container With Most Water相关的知识,希望对你有一定的参考价值。

public class Solution {
    public int maxArea(int[] height) {
        int maxa = 0;
        int maxi = 0;
        if(height.length<2)
            return 0;
        for(int i=0;i<height.length-1;i++){
            if(height[i]<height[maxi]){
                continue;                
            }
            for(int j=height.length-1;j>i;j--){
                if(height[j]>height[i]){
                    int maxmid = (j-i)*height[i];
                    maxa = maxa>maxmid?maxa:maxmid;
                    break;
                }
                else{
                    int maxmid = (j-i)*height[j];
                    maxa = maxa>maxmid?maxa:maxmid;
                }
            }
            maxi = i;
        }
        return maxa;
    }
}

 

以上是关于Leetcode Array 11 Container With Most Water的主要内容,如果未能解决你的问题,请参考以下文章

解决:Unexpected token (START_OBJECT), expected START_ARRAY: need JSON Array to contain As.WRAPPER_ARRA

skopt 的 gp_minimize() 函数引发 ValueError: array must not contain infs or NaNs

LeetCode11.Array and String —Array Partition I 数组分区

[Leetcode Week11]Kth Largest Element in an Array

Leetcode Array 11 Container With Most Water

Count and Say (Array Length Encoding) -- LeetCode