37. Count Square Submatrices with All Ones
Given a m * n
matrix of ones and zeros, return how many square submatrices have all ones.
Example 1:
Example 2:
Approach
The idea is to scan each cell in the matrix
to update the placeholder result
variable with the number of squares that can be formed from the currently looking cell (when it is the bottom right corner cell of the any possible square).
Solution: (Dp)
Time Complexity: O(n * m)
Last updated