题目:
题解:
int maximalRectangle(char** matrix, int matrixSize, int* matrixColSize) {
int m = matrixSize;
if (m == 0) {
return 0;
}
int n = matrixColSize[0];
int left[m][n];
memset(left, 0, sizeof(left));
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (matrix[i][j] == '1') {
left[i][j] = (j == 0 ? 0 : left[i][j - 1]) + 1;
}
}
}
int ret = 0;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (matrix[i][j] == '0') {
continue;
}
int width = left[i][j];
int area = width;
for (int k = i - 1; k >= 0; k--) {
width = fmin(width, left[k][j]);
area = fmax(area, (i - k + 1) * width);
}
ret = fmax(ret, area);
}
}
return ret;
}