Last active
January 14, 2018 13:27
-
-
Save tcw165/ce49b7464b0572a97e745a23c23897a7 to your computer and use it in GitHub Desktop.
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 int largestRectanglularAreaInHistogram(int[] hist) { | |
int maxArea = 0; | |
// Iterate through the histogram. | |
for (int i = 0; i < hist.length; ++i) { | |
int h = hist[i]; | |
maxArea = Math.max(maxArea, h); | |
for (int j = i - 1; j >= 0; --j) { | |
final int w = (i - j + 1); | |
h = Math.min(h, hist[j]); | |
maxArea = Math.max(maxArea, h * w); | |
} | |
} | |
return maxArea; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment