LeetCode 11. Container With Most Water

public class Solution {
    public int maxArea(int[] height) {
        int i=0,j=height.length-1;
		 int maxarea=0;
		 int area=0;
		 while(i<j)
		 {
			 if(height[i]<height[j])
				 {area = (j-i)*height[i];
				 i++;
				 }
				 
			 else
			 {
				 area = (j-i)*height[j];
			     j--;
			 }
			 if(area>maxarea)
				 maxarea = area;
			
		 }
		return maxarea;

		
	        
    }
}

你可能感兴趣的:(Algorithm,LeetCode)