90%+ faster Python solution, with 90% + space reduction
\nclass Solution:\n    def countSquares(self, matrix: List[List[int]]) -> int:\n        m = len(matrix)\n        n = len(matrix[0])\n        s = 0\n        for 
```\nclass Solution:\n    def countSquares(self, matrix: List[List[int]]) -> int:\n        m = len(matrix)\n        n = len(matrix[0])\n        s = 0\n        for i in range(0, m):\n            for j in range(0, n):\n                if matrix[i][j] == 1:\n                    if i == 0 or j == 0:\n                        matrix[i][j] = 1\n                    else:\n                        matrix[i][j] = (1 + min(matrix[i-1][j], matrix[i-1][j-1], matrix[i][j-1]))\n                    s += matrix[i][j]\n        return s\n```
[]