LeetCode 221: Maximal Square
Posted keepshuatishuati
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode 221: Maximal Square相关的知识,希望对你有一定的参考价值。
Note:
For square, the minimum size of topleft and top and left decides the square of the result.
class Solution { public int maximalSquare(char[][] matrix) { if (matrix.length == 0) return 0; int result = 0; int[][] dp = new int[matrix.length + 1][matrix[0].length + 1]; for (int i = 1; i <= matrix.length; i++) { for (int j = 1; j <= matrix[0].length; j++) { if (matrix[i - 1][j - 1] == ‘1‘) { dp[i][j] = Math.min(Math.min(dp[i - 1][j], dp[i][j - 1]), dp[i - 1][j - 1]) + 1; result = Math.max(dp[i][j], result); } } } return result*result; } }
以上是关于LeetCode 221: Maximal Square的主要内容,如果未能解决你的问题,请参考以下文章
[Leetcode] 221. Maximal Square
[Leetcode221]最大面积 Maximal Square
[LeetCode] 221. Maximal Square 最大正方形