Largest All-One Square Area
Problem statement
You are given a nonempty rectangular binary matrix matrix. Find the largest square whose cells all contain 1, and return its area.
A square uses consecutive rows and consecutive columns. Return 0 when the matrix contains no 1.
Function
maximalSquareArea(matrix: int[][]) → intExamples
Example 1
matrix = [[1,1,1],[1,1,1]]return = 4A square can have side length 2, even though the all-one rectangle is wider.
Example 2
matrix = [[1,1,0],[1,1,1],[0,1,1]]return = 4There are two overlapping squares of side length 2; the whole matrix is not all ones.
Example 3
matrix = [[0,0],[0,0]]return = 0No all-one cell exists, so the largest square has area 0.
Constraints
1 <= matrix.length, matrix[0].length <= 300.- Every row has the same length.
- Every cell is
0or1.