1 2 3 4 5 6 7 8 9 10 11 12 13 14 | public class Solution { public int maxArea(int[] height) { if (height == null||height.length==0) return 0; int left = 0; int right = height.length-1; int curMax = 0; while (left < right){ curMax = Math.max(Math.min(height[left], height[right])*(right-left), curMax); if (height[left] > height[right]) right--; else left++; } return curMax; } } |
No comments:
Post a Comment