Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public int maxArea(int[] height) {
- int left = 0;
- int right = height.length-1;
- int maxArea = 0;
- while (left < right) {
- int currentArea = calculateArea(height, left, right);
- maxArea = Math.max(maxArea, currentArea);
- if (height[left] < height[right]) {
- ++left;
- } else {
- --right;
- }
- }
- return maxArea;
- }
- public int calculateArea(int[] height, int left, int right) {
- return Math.min(height[left], height[right]) * (right-left);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement