Approach: Use the histogram max rectangle area.
public int MaximalRectangle(char[][] matrix)
{
if (matrix == null || matrix.Length == 0)
{
return 0;
}
int maxRect = 0;
int[] tempStorage = new int[matrix[0].Length];
for (int i = 0; i <matrix.Length; ++i)
{
for (int j = 0; j < matrix[0].Length; ++j)
{
if (matrix[i][j] == '0')
{
tempStorage[j] = 0;
}
else
{
tempStorage[j] += matrix[i][j] - '0';
}
}
int maxArea = this.LargestRectangleArea(tempStorage);
maxRect = maxRect < maxArea ? maxArea : maxRect;
}
return maxRect;
}
No comments:
Post a Comment