Clean Python DP solution
\nclass Solution:\n    def countSquares(self, matrix: List[List[int]]) -> int:\n        res = 0\n        for i in range(len(matrix)):\n            for j in rang
```\nclass Solution:\n    def countSquares(self, matrix: List[List[int]]) -> int:\n        res = 0\n        for i in range(len(matrix)):\n            for j in range(len(matrix[0])):\n                if matrix[i][j] == 0:\n                    continue\n                if i == 0 or j == 0:\n                    res += 1\n                else:\n                    matrix[i][j] = min(min(matrix[i][j-1], matrix[i-1][j]), matrix[i-1][j-1])+1\n                    res += matrix[i][j]\n        return res\n```
[]