Java DP intuitive & concise solution with explaination
Idea: Idea is based on this problem:\nhttps://leetcode.com/problems/maximal-square/\n\ndp[i][j] represents the length of the square which lower right corner is 
Idea: Idea is based on this problem:\nhttps://leetcode.com/problems/maximal-square/\n\ndp[i][j] represents the length of the square which lower right corner is located at (i, j).\nIf the value of this cell is also 1, then the length of the square is the minimum of: the one above, its left, and diagonal up-left value +1. Because if one side is short or missing, it will not form a square.\n\n\n```\npublic int countSquares(int[][] matrix) {\n        int total = 0;\n        int rows = matrix.length;\n        int cols = matrix[0].length;\n        for(int i = 0; i < rows; i++){\n            for(int j = 0; j < cols; j++){\n                if(matrix[i][j] == 0)\n                    continue;\n                if(i == 0 || j == 0){\n                    total += matrix[i][j];\n                    continue;\n                }\n                int min = Math.min(matrix[i-1][j], Math.min(matrix[i][j-1], matrix[i-1][j-1]));\n                matrix[i][j] += min;\n                total += matrix[i][j];\n            }\n        }\n        return total;\n    }\n```
[]