✅ Simple Java Solution
CODE\nJava []\npublic int countSquares(int[][] matrix) {\n\tint r = matrix.length, c=matrix[0].length, count = 0;\n\n\tfor(int i=0; i<r; i++){\n\t\tfor(int j=0;
## **CODE**\n```Java []\npublic int countSquares(int[][] matrix) {\n\tint r = matrix.length, c=matrix[0].length, count = 0;\n\n\tfor(int i=0; i<r; i++){\n\t\tfor(int j=0; j<c; j++){\n\t\t\tif(matrix[i][j] == 1){\n\t\t\t\tif(i > 0 && j > 0){\n\t\t\t\t\tmatrix[i][j] = Math.min(matrix[i-1][j-1], Math.min(matrix[i-1][j],matrix[i][j-1]))+1;\n\t\t\t\t}\n\t\t\t\tcount += matrix[i][j];   \n\t\t\t}\n\t\t}\n\t}\n\n\treturn count;\n}\n```
['Dynamic Programming', 'Java']