Share my solution in Java


  • 0
    H
    public class Solution {
        public int maxArea(int[] height) {
            int low = 0;
            int high = height.length - 1;
            int max = 0;
            int temp = 0;
            while(low < high){
                temp = (high - low) * (height[high] < height[low] ? height[high] : height[low]);
                if(temp > max){
                    max = temp;
                }
                if(height[high] > height[low]){
                    low++;
                }
                else
                {
                    high--;
                }
            }
            return max;
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.