题目描述:
题解:
代码:
class Solution {
public:
int maximalSquare(vector<vector<char>>& matrix) {
int m = matrix.size();
int n = matrix[0].size();
vector<vector<int>> dp(m+1,vector<int>(n+1,0));
int l_max = 0;
//matrix 为 m行n列
for(int i = 1;i<=m;i++)
{
for(int j=1;j<=n;j++)
{
if(matrix[i-1][j-1]=='1')
{
dp[i][j] = min(dp[i-1][j-1],min(dp[i][j-1],dp[i-1][j]))+1;
l_max = max(dp[i][j],l_max);
}
}
}
return l_max*l_max;
}
};
注意:min(dp[i-1][j-1],dp[i][j-1],dp[i-1][j]) 会报错