My 3ms solution for Container With Most Water

  • 0
    public int maxArea(int[] height) {
          int maxRes = Integer.MIN_VALUE;
    		int maxHeight;
    		int tmpRes;
    		int leftPointer =0,rightPointer = height.length-1;
    			tmpRes = rightPointer-leftPointer;
    			// judge if the left pointer's height bigger?
    			if (height[leftPointer]<height[rightPointer]) {
    				maxHeight =  height[leftPointer++];
    			}else {
    				maxHeight = height[rightPointer--];
    			// to get the result of result now
    			tmpRes = maxHeight*tmpRes;
    			// get the max result
    			if (tmpRes>maxRes) {
    				maxRes = tmpRes;
    		return maxRes;

Log in to reply

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