盛水最多的容器

双指针思路即可。

  public int maxArea (int[] height) {
        // write code here

        int i=0,j=height.length-1;

        int max=0;

        while (i<j){

            int area=Math.min(height[j],height[i])*(j-i);
            max=Math.max(max,area);

            if(height[j]>=height[i]) i++;
            else j--;
            
        }
        
        return max;
    }



全部评论

相关推荐

asdasdasda...:19岁,不容易啊可能升个本会好点,现在学历歧视太严重了
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务