maximal-square
Problem
Problem Description
Solution
This is dynamic programming, which can solve it by breaking down into smaller subproblems. DP problem, the hard part is to come up with formular function, first we init dp:
m, represents rows of the matrix
n, represents columns of the matrix
dp[m+1][n+1]
dp formular function:
for each matrix[i-1][j-1]='1'
, update max, max=max(max, dp[i][j]
After iterate matrix, we get the maximum edge of square, return max * max;
For example:
Complexity Analysis
Time Complexity: O(N*M)
Space Complexity: O(N*M)
N - the number of rows of matrix
M - the number of columns of matrix
Code
Last updated