标签:style blog class code c java
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.
Note: You may not slant the container.
public class Solution { public int maxArea(int[] height) { if(height.length<2) return 0; int re=0; int j=height.length-1; int i=0; while(j>i){ if(height[i]>=height[j]){ int area = height[j]*(j-i); if(area>re) re=area; j--; continue; }else{ int area=height[i]*(j-i); if(area>re) re=area; i++; continue; } } return re; } }
【LeetCode】Container With Most Water,布布扣,bubuko.com
【LeetCode】Container With Most Water
标签:style blog class code c java
原文地址:http://www.cnblogs.com/yixianyixian/p/3725486.html