C++ || Easy to Understand DP problem ||
\tclass Solution {\n\tpublic:\n    int countSquares(vector>& matrix) {\n        int count=0;\n        for(int i=0;i<matrix[0].size();++i)\n            if(matrix
\tclass Solution {\n\tpublic:\n    int countSquares(vector<vector<int>>& matrix) {\n        int count=0;\n        for(int i=0;i<matrix[0].size();++i)\n            if(matrix[0][i]==1)\n                count++;\n        for(int i=1;i<matrix.size();++i)\n            if(matrix[i][0]==1)\n                count++;\n        for(int i=1;i<matrix.size();++i){\n            for(int j=1;j<matrix[0].size();++j){\n                if(matrix[i][j]==1){\n                    count++;\n                    if(matrix[i-1][j]!=0 && matrix[i-1][j-1]!=0 && matrix[i][j-1]!=0){\n                        int val=min(matrix[i-1][j],min(matrix[i-1][j-1],matrix[i][j-1]));\n                        matrix[i][j]=val+1;\n                            count+=matrix[i][j]-1;\n                    }\n                }\n            }\n        }\n        return count;\n    }\n\t};
[]