EASY UNDERSTANDING JAVA SOLYTION WITH PICTURE IN IT ||O(N*M)
\n\n\n\n\n\nclass Solution \n{\n    public int countSquares(int[][] matrix)\n    {\n        int n=matrix.length;\n        int m=matrix[0].length;\n        int d
![image](https://assets.leetcode.com/users/images/ee179d45-f709-47be-90a2-b2c53a78730a_1633498886.4443843.jpeg)\n![image](https://assets.leetcode.com/users/images/68579e03-88f0-4258-a66c-a78ab81c1a0f_1633498888.6313012.jpeg)\n![image](https://assets.leetcode.com/users/images/31b6484b-7b80-41b2-9b82-ae788953343d_1633498890.4995248.jpeg)\n\n\n```\nclass Solution \n{\n    public int countSquares(int[][] matrix)\n    {\n        int n=matrix.length;\n        int m=matrix[0].length;\n        int dp[][]=new int[n][m];\n        for(int i=0;i<n;i++)\n        {\n              dp[i][0]=matrix[i][0];\n        }\n        for(int i=0;i<m;i++)\n        {\n              dp[0][i]=matrix[0][i];\n        }\n        for(int i=1;i<n;i++)\n        {\n            for(int j=1;j<m;j++)\n            {\n                if(matrix[i][j]==1)\n                dp[i][j]=1+Math.min(dp[i-1][j-1],Math.min(dp[i][j-1],dp[i-1][j]));\n            }\n        }\n       \n        int sum=0;\n        for(int i=0;i<n;i++)\n        {\n            for(int j=0;j<m;j++)\n            {\n                sum+=dp[i][j];\n            }\n        }\n        \n        return sum;\n        \n    }\n}\n```\n\n```\nif u like pls upvote\n```
['Dynamic Programming', 'Java']