标签:win art 描述 fragment turn appdata 技术 正方形 row
题目描述:
方法一:动态规划
class Solution: def maximalSquare(self, matrix: List[List[str]]) -> int: if not matrix: return 0 row = len(matrix) col = len(matrix[0]) dp = [[0 for _ in range(col+1)] for _ in range(row + 1)] res = 0 for i in range(row): for j in range(col): if matrix[i][j]==‘1‘: dp[i+1][j+1] = min(dp[i+1][j],dp[i][j],dp[i][j+1])+1 res = max(res, dp[i+1][j+1] ** 2) return res
class Solution: def maximalSquare(self, matrix: List[List[str]]) -> int: res=0 for i in range(len(matrix)): for j in range(len(matrix[0])): matrix[i][j]=int(matrix[i][j]) if i==0 or j==0: res=max(res,matrix[i][j]) continue if matrix[i][j]==0:continue matrix[i][j]=min(matrix[i-1][j],matrix[i][j-1],matrix[i-1][j-1])+1 res=max(res,matrix[i][j]) return res**2
标签:win art 描述 fragment turn appdata 技术 正方形 row
原文地址:https://www.cnblogs.com/oldby/p/11622393.html