本文主要是介绍C语言 | Leetcode C语言题解之第85题最大矩形,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目:
题解:
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;
}
这篇关于C语言 | Leetcode C语言题解之第85题最大矩形的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!