Python3 simple solution beats 80% users
\nclass Solution:\n    def countSquares(self, matrix: List[List[int]]) -> int:\n        count = 0\n        for i in range(len(matrix)):\n            for j in ra
```\nclass Solution:\n    def countSquares(self, matrix: List[List[int]]) -> int:\n        count = 0\n        for i in range(len(matrix)):\n            for j in range(len(matrix[0])):\n                if matrix[i][j] == 1 and (i != 0 and j != 0):\n                    matrix[i][j] = min(matrix[i-1][j-1], matrix[i-1][j], matrix[i][j-1])+1\n            count += sum(matrix[i])\n        return count\n```\n**If you like this solution, please upvote for this**
['Python3']