[C++] DP + Iterative, Easy solution
The best description can be found in this video with step by step approach of how to build an intuition and solution.\n\n\nBelow is an easy to understand the so
The best description can be found in [***this video***](https://www.youtube.com/watch?v=FO7VXDfS8Gk&t=943s) with step by step approach of how to build an intuition and solution.\n\n\nBelow is an easy to understand the solution that follows the approach discussed in the video above.\n(I could explain it in this text but I might miss a few details. It\'s better to go through the video to understand in entirety.)\n\n```\nclass Solution {\npublic:\n    int countSquares(vector<vector<int>>& matrix) {\n        int result = 0;\n        \n        for(int i = 0; i<matrix.size(); i++)\n        {\n            for(int j = 0; j<matrix[0].size(); j++)\n            {\n                if(i > 0 && j > 0 && matrix[i][j]>0)\n                    matrix[i][j] = min(matrix[i-1][j-1], min(matrix[i-1][j], matrix[i][j-1])) + 1;\n                \n                result += matrix[i][j];\n            }\n        }\n        \n        return result;\n    }\n};\n```
['Dynamic Programming', 'C', 'Iterator', 'C++']