✔️[C++] || Very Very Simple Code || Easy to understand || TC: O( n*m ) , SC: O( 1 )
Please Upvote if it helps\u2B06\uFE0F\n\n\tint countSquares(vector<vector<int>>& matrix) {\n        int n=matrix.size(),m=matrix[0].size(),ans=0;\n        for(i
#### *Please Upvote if it helps\u2B06\uFE0F*\n```\n\tint countSquares(vector<vector<int>>& matrix) {\n        int n=matrix.size(),m=matrix[0].size(),ans=0;\n        for(int i=0;i<n;++i){\n            for(int j=0;j<m;++j){\n                if(matrix[i][j]==1){\n                    if(i==0 || j==0) ans++;\n                    else{\n                        matrix[i][j]+=min(matrix[i-1][j-1],min(matrix[i-1][j],matrix[i][j-1]));\n                        ans+=matrix[i][j];\n                    }\n                }\n            }\n        }\n        return ans;\n    }\n```\nThe detail and great explanation of this question is https://leetcode.com/problems/count-square-submatrices-with-all-ones/discuss/643429/Python-DP-Solution-%2B-Thinking-Process-Diagrams-(O(mn)-runtime-O(1)-space)
['Dynamic Programming', 'C']