链接https://www.bilibili.com/video/av374033867/

class Solution: def solve(self , matrix: List[List[str]]) -> int: if len(matrix)==0:return 0 dp=[ [0 for i in range(len(matrix[0]))] for j in range(len(matrix)) ] for i in range(len(matrix)): if matrix[i][0]=="1": dp[i][0]=1 for j in range(len(matrix[0])): if matrix[0][j]=="1": dp[0][j]=1 res=0 for hang in range(1,len(matrix)): for lie in range(1,len(matrix[0])): if matrix[hang][lie]=="1": dp[hang][lie]=min(dp[hang][lie-1],dp[hang-1][lie],dp[hang-1][lie-1]) + 1 if dp[hang][lie]>res:res=dp[hang][lie] return res*res