Created
May 22, 2018 22:25
-
-
Save Siyu-Lei/a13b2e64411d000293840520887f6182 to your computer and use it in GitHub Desktop.
This file contains 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
class Solution { | |
public int maxArea(int[] height) { | |
int start = 0; | |
int end = height.length - 1; | |
int max = 0; | |
while (start < end) { | |
int min = Math.min(height[start], height[end]); | |
max = Math.max(min * (end - start), max); | |
while (height[start] <= min && start < end) { | |
start++; | |
} | |
while (height[end] <= min && start < end) { | |
end--; | |
} | |
} | |
return max; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment