My Simple Java DP Solution
java\nclass Solution {\n    public int countSquares(int[][] matrix) {\n        int m = matrix.length;\n        int n = matrix[0].length;\n        if(m==1 && n==
```java\nclass Solution {\n    public int countSquares(int[][] matrix) {\n        int m = matrix.length;\n        int n = matrix[0].length;\n        if(m==1 && n==1) return matrix[0][0];\n        int count = 0;\n        \n        int [][] dp = new int [m+1][n+1];\n        \n        for(int i =1; i<=m; i++){\n            for(int j=1; j<=n; j++){\n                if(matrix[i-1][j-1] ==1){\n                    int a = dp[i-1][j-1];\n                    int b = dp[i-1][j];\n                    int c = dp[i][j-1];\n                    if(a ==0 || b == 0 || c ==0) dp[i][j] =1;\n                    else if (a ==b && b ==c) dp[i][j] = a+1;\n                    else dp[i][j] = Math.min(Math.min(a,b), Math.min(a,c)) +1;\n                    \n                }\n                count+=dp[i][j];\n            }\n            \n        }\n        return count;\n    }\n}\n```
['Dynamic Programming', 'Java']