Tabulation || C++ || Easy
\n# Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) \n    O(m X n)\n\n- Space complexity:\n Add your space complexity here, e.g. O(n) 
\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n    O(m X n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n    O(m X n)\n# Code\n```\nclass Solution {\npublic:\n    int countSquares(vector<vector<int>>& matrix) {\n        int m=matrix.size(),n=matrix[0].size(),sum=0;\n        for(int i=1;i<m;i++){\n            for(int j=1;j<n;j++){\n                \n                    if(matrix[i][j]==1)\n                    matrix[i][j]=min(matrix[i-1][j-1],min(matrix[i][j-1],matrix[i-1][j]))+1;\n                \n            }\n        }\n        for(int i=0;i<m;i++){\n            for(int j=0;j<n;j++){\n                sum+=matrix[i][j];\n            }\n        }\n        return sum;\n    }\n};\n```
['C++']