Shawngbk / Leecode

Questions of Leecode
0 stars 0 forks source link

11. Container With Most Water #151

Open Shawngbk opened 7 years ago

Shawngbk commented 7 years ago

public class Solution { public int maxArea(int[] height) { int maxarea = Integer.MIN_VALUE; int left = 0; int right = height.length - 1; while(left < right) { //面积是底乘以小的那一条高,木桶原理 maxarea = Math.max(maxarea, Math.min(height[left], height[right]) * (right - left)); if(height[left] < height[right]) { left++; } else { right--; } } return maxarea; } }

Shawngbk commented 7 years ago

bloomberg