Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. class Solution {
  2.     public int maxArea(int[] height) {
  3.         int left = 0;
  4.         int right = height.length-1;
  5.         int maxArea = 0;
  6.         while (left < right) {
  7.             int currentArea = calculateArea(height, left, right);
  8.             maxArea = Math.max(maxArea, currentArea);
  9.             if (height[left] < height[right]) {
  10.                 ++left;
  11.             } else {
  12.                 --right;
  13.             }
  14.         }
  15.         return maxArea;
  16.     }
  17.     public int calculateArea(int[] height, int left, int right) {
  18.         return Math.min(height[left], height[right]) * (right-left);
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement