Beat 79% Simple JAVA Solution


  • 0
    J

    public class Solution {
    public int maxArea(int[] height) {
    if(height == null || height.length < 2 ) return 0;
    int len = height.length,max = 0,cure,cureIndex,candi,temp;

        int start = 0,end  = len - 1;
        
        cure = height[0];
        
        while(start < end) {
            
            if(height[start] > height[end]) {
                temp = (end-start)*height[end];
                if(temp > max) max = temp;
                cure = height[end];
                cureIndex = end;
                end--;
            }
            else {
                temp = (end-start)*height[start];
                if(temp > max) max = temp;
                cure = height[start];
                cureIndex = start;
                start++;
            }
        }
        
        return max;
    }
    

    }


Log in to reply
 

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