[Java] Simple DP solution
Time Complexity = O(row*column)\nSpace Complexity = O(1)\n\n\npublic int countSquares(int[][] matrix) {\n        int r = matrix.length;\n        int c = matrix[
Time Complexity = O(row*column)\nSpace Complexity = O(1)\n\n```\npublic int countSquares(int[][] matrix) {\n        int r = matrix.length;\n        int c = matrix[0].length;\n        int ans = 0;\n        \n        for(int i = 0;i<r;i++) {\n            for(int j = 0;j<c;j++)\n            {\n                if(i == 0 || j == 0)\n                    ans += matrix[i][j];\n                else if(matrix[i][j] == 1) {\n                    matrix[i][j] = 1 + Math.min(matrix[i-1][j], \n                                       Math.min(matrix[i][j-1], matrix[i-1][j-1]));\n                    ans += matrix[i][j];\n                }\n            }\n        }\n        \n        return ans;\n    }\n```\n\n
[]