221. Maximal Square
https://leetcode.com/problems/maximal-square/description/
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.
Example:
Thoughts
01矩阵返回内部由1组成的最大方阵的大小。argmax + 格子 => DP。dp[i][j]表示在(i, j)处最大方阵边长是多少,当它是1时,它由左,上和斜能构成的最大方阵拼接而成,且大小受制于邻居中最小的。总结果是argmax_(i, j),所有子结果中最优的。
Code
Analysis
Errors:
m == 0 || matrix[0] == null没考虑
return pow(2, max)
时间复杂度O(mn).
Last updated
Was this helpful?