MCPcopy Create free account
hub / github.com/Blankj/awesome-java-leetcode / Solution

Class Solution

src/com/blankj/medium/_0011/Solution.java:11–29  ·  view source on GitHub ↗

author: Blankj blog : http://blankj.com time : 2017/04/23 desc :

Source from the content-addressed store, hash-verified

9 * </pre>
10 */
11public 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected