[C++][Maximum Size Square] DP solution


#1
int Solution::solve(vector<vector<int> > &A) {
    int m = A.size(), n = A[0].size(), maxEdgeLen = 0;
    for(int i=0; i<m; i++) 
        for(int j=0; j<n; j++){
            if(A[i][j] == 0)    continue;
            int a = i>0 && j>0 ? A[i-1][j-1] : 0;
            int b = i>0 ? A[i-1][j] : 0;
            int c = j>0 ? A[i][j-1] : 0;
            A[i][j] = max(A[i][j], min({a,b,c})+1);
            maxEdgeLen = max(maxEdgeLen, A[i][j]);   
        }
    return maxEdgeLen*maxEdgeLen;
}