Given a 2D binary matrix filled with 0’s and 1’s, find the largest square containing only 1’s and return its area.
For example, given the following matrix:
Return 4.
解法1:
诀窍在于dp[i][j] 表示以(i,j)为底的正方形的边长。
dp[i][j] = min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]) + 1, if matrix[i][j] == 1,
画一下图就比较清楚。
C++
Java