Untitled
unknown
plain_text
a year ago
607 B
1
Indexable
Never
class Solution { public: int maximalSquare(vector<vector<char>>& mat) { if(mat.empty()) return 0; int r=mat.size(),c =mat[0].size(); int sz=0; vector<vector<int>> dp(r,vector<int>(c,0)); for(int i=0;i<r;i++){ for(int j=0;j<c;j++){ if(!i || !j || mat[i][j]=='0') dp[i][j]=mat[i][j]-'0'; // store 0, cant form square else{ dp[i][j]=1 + min(dp[i-1][j],min(dp[i-1][j-1],dp[i][j-1])); } sz=max(sz,dp[i][j]); } } return sz*sz; } };