SHARE
TWEET

Untitled

a guest Sep 17th, 2019 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top