Some question about this problem


  • 0
    X
     public int maxArea(int[] height) {
    		if (height == null || height.length <= 1) {
    			return -1;
    		}
    		// set two pointer
    		int left = 0;	// left pointer
    		int right = height.length - 1;	// right pointer
    		int maxArea = 0;
    		while (left < right) {
    			maxArea = Math.max(maxArea, (right - left) * Math.min(height[left], height[right]));
    			// left is the 瓶颈, 无论怎么向左移动right都无法得到比当前面积更大的了
    			if (height[left] <= height[right]) {
    				left++;
    			} else {
    			    //rightMax 是瓶颈
    				right--;
    			}
    		}
    		return maxArea;
    	}
    

    this code will get TLE, however if I change the:

    if (height[left] < height[right]) {
    	left++;
    }
    

    I will get AC.
    So, what's the difference?


  • 0

    @xiaowu4 said in Some question about this problem:

    this code will get TLE

    No it won't.


  • 0
    X

    @StefanPochmann Let me try angin


Log in to reply
 

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