very simple java solution
\nclass Solution {\n    public int countSquares(int[][] matrix) {\n        \n        int sum=0;\n        for(int i=0;i<matrix.length;i++)\n        {\n          
```\nclass Solution {\n    public int countSquares(int[][] matrix) {\n        \n        int sum=0;\n        for(int i=0;i<matrix.length;i++)\n        {\n            for(int j=0;j<matrix[i].length;j++){\n                if(i!=0 && j!=0 && matrix[i][j]!=0){\n                matrix[i][j]=Math.min(Math.min(matrix[i][j-1]  ,matrix[i-1][j-1]), matrix[i-1][j])+1;\n                }\n                sum+=matrix[i][j];\n            }\n        }\n        return sum;\n    }\n}\n```
['Dynamic Programming', 'Java']