示例 3:
输入:matrix = [["0"]] 输出:0
# 最大正方形面积
def max_square(matrix):
m = len(matrix)
n = len(matrix[0])
if m == 0 or n == 0::
return None
max_side = 1
dp = [[0] * (n + 1) for _ in range(m + 1)]
for i in range(1, m + 1):
for j in range(1, n + 1):
if matrix[i][j] == 1:
dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1 ]) + 1
max_side = max(max_side, dp[i][j])
return max_side * max_side