Advanced
Open
Pro
Largest Square in a Matrix
Given an m x n binary matrix matrix filled with 0s and
1s, find the largest square containing only 1s, and return
its area.
Example 1
Input:
matrix = [
[1, 0, 1, 0, 0],
[1, 0, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 0, 0, 1, 0],
]
Output: 4
Explanation: The largest all-1s square has side length 2, area 4.
Example 2
Input: matrix = [[0, 1], [1, 0]]
Output: 1
Constraints
1 <= m, n <= 300matrix[i][j]is0or1.
Share this question