Maximal Square
ID:221
Last updated
ID:221
Last updated
Given an m x n
binary matrix
filled with 0
's and 1
's, find the largest square containing only 1
's and return its area.
If a cell is surrounded by 1s, this cell can form a new square with 1 more length ([i-1][j], [i][j-1][i-1][j-1] all 1, [i][j] can form a 2x2 square)
Extensively, if ([i-1][j], [i][j-1][i-1][j-1] all already in a 2x2 square, [i][j] can form a 3x3 square)
So, heuristic: dp[i][j] = Min(dp[i-1][j], dp[i][j-1], dp[i-1][j-1]) + 1