Python O(m*n) 652 ms, faster than 81.06%
\nclass Solution:\n    def countSquares(self, matrix: List[List[int]]) -> int:\n        count = 0\n        nb_row = len(matrix)\n        nb_col = len(matrix[0])
```\nclass Solution:\n    def countSquares(self, matrix: List[List[int]]) -> int:\n        count = 0\n        nb_row = len(matrix)\n        nb_col = len(matrix[0])\n        for i in range(nb_row):\n            count += matrix[i][0]\n        for j in range(1, nb_col):\n            count += matrix[0][j]\n        for i in range(1, nb_row):\n            for j in range(1, nb_col):\n                if matrix[i][j] == 1:\n                    matrix[i][j] = min(matrix[i-1][j-1], matrix[i-1][j], matrix[i][j-1])+1\n                    count += matrix[i][j]\n        return count\n```
['Python', 'Python3']