Largest Square of Ones
Problem statement
Given a rectangular binary matrix matrix, return the side length of the largest square submatrix composed only of 1 values.
If the matrix contains no 1, return 0.
Function
findLargestSquare(matrix: int[][]) → intExamples
Example 1
matrix = [[1,1,0,1,0],[1,1,1,1,1],[0,0,1,1,1],[0,0,1,1,1],[1,1,0,0,0]]return = 3The rows and columns from index 1 through 3 contain a 3 x 3 square of ones.
Example 2
matrix = [[0,0],[0,0]]return = 0No cell contains 1.
Example 3
matrix = [[1]]return = 1The single cell is itself a square of side length 1.
Constraints
1 <= matrix.length <= 500.1 <= matrix[i].length <= 500.- Every row has the same length.
- Every value is either
0or1.