author: Blankj blog : http://blankj.com time : 2017/04/23 desc :
| 9 | * </pre> |
| 10 | */ |
| 11 | public class Solution { |
| 12 | public int maxArea(int[] height) { |
| 13 | int l = 0, r = height.length - 1; |
| 14 | int max = 0, h = 0; |
| 15 | while (l < r) { |
| 16 | h = Math.min(height[l], height[r]); |
| 17 | max = Math.max(max, (r - l) * h); |
| 18 | while (height[l] <= h && l < r) ++l; |
| 19 | while (height[r] <= h && l < r) --r; |
| 20 | } |
| 21 | return max; |
| 22 | } |
| 23 | |
| 24 | public static void main(String[] args) { |
| 25 | Solution solution = new Solution(); |
| 26 | System.out.println(solution.maxArea(new int[]{1, 2, 4, 3})); // 4 |
| 27 | System.out.println(solution.maxArea(new int[]{1, 8, 6, 2, 5, 4, 8, 3, 7}));// 49 |
| 28 | } |
| 29 | } |
nothing calls this directly
no outgoing calls
no test coverage detected