Created
June 28, 2017 14:45
gist for leetcode 11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public int maxArea(int[] height) { | |
int ans = 0; | |
int left = 0, right = height.length-1; | |
while(left < right) { | |
if(height[left] < height[right]) { | |
ans = Math.max(ans, (right-left) * height[left]); | |
++left; | |
} | |
else { | |
ans = Math.max(ans, (right-left) * height[right]); | |
--right; | |
} | |
} | |
return ans; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment