DP one vector soln based on Maximal Square
\nclass Solution {\npublic:\n    int countSquares(vector<vector<int>>& matrix) {\n        int m=matrix.size(), n=matrix[0].size(), result=0;\n        vector<int
```\nclass Solution {\npublic:\n    int countSquares(vector<vector<int>>& matrix) {\n        int m=matrix.size(), n=matrix[0].size(), result=0;\n        vector<int> dp(n+1, 0);\n        \n        for(int i=1; i<=m; i++){\n            int prev=dp[0];\n            \n            for(int j=1; j<=n; j++){\n                if(matrix[i-1][j-1] == 0){\n                    dp[j]=0;\n                    continue;\n                }\n                int temp = dp[j];\n                dp[j] = 1 + min(prev, min(dp[j-1], dp[j]));\n                prev = temp;\n                result += dp[j];\n            }\n        }\n        return result;\n    }\n};\n\n/*\n\n1. dp arr, take max square value\n2. keep size count\n3. from 1 to cur max, increment counts\n\n*/\n```\nI appreciate your upvote !!
['Dynamic Programming', 'C', 'C++']