###### 【Leetcode】Maximal Square

Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.

For example, given the following matrix:

1 0 1 0 0
1 0 1 1 1
1 1 1 1 1
1 0 0 1 0

Return 4.

public int maximalSquare(char[][] matrix) {
if (matrix.length == 0)
return 0;
int max = 0;
int c[][] = new int[matrix.length][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') {
continue;
}
if (i == 0 || j == 0) {// 在边缘时
c[i][j] = 1;
} else {
c[i][j] = Math.min(c[i - 1][j - 1], Math.min(c[i - 1][j], c[i][j - 1])) + 1;
}
max = Math.max(max, c[i][j]);
}
}
return max * max;
}  

#### leetcode 221: Maximal Square

2015-06-05 08:15:01

#### LeetCode221:Maximal Square

2015-06-18 22:53:12

#### LeetCode(221) Maximal Square

2015-08-10 21:53:25

#### [leetcode] 221 Maximal Square(最大全1正方形 &动态规划)

2015-10-04 23:04:17

#### 221. Maximal Square | Java最短代码实现

2016-03-24 10:20:10

#### 算法学习之动态规划(leetcode 85. Maximal Rectangle）

2017-03-15 16:59:00

#### leetcode_question_85 Maximal Rectangle

2013-09-19 17:29:08

#### LeetCode85——Maximal Rectangle

2016-01-28 20:44:55

#### LeetCode 85 Maximal Rectangle (Python详解及实现)

2017-08-09 16:37:19

#### LeetCode --- 85. Maximal Rectangle

2015-04-03 17:09:12

## 不良信息举报

【Leetcode】Maximal Square