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

Method maxArea

src/com/blankj/medium/_0011/Solution.java:12–22  ·  view source on GitHub ↗
(int[] height)

Source from the content-addressed store, hash-verified

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();

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected