Python DFS solution
\nclass Solution(object):\n    def findCircleNum(self, M):\n        """\n        :type M: List[List[int]]\n        :rtype: int\n        """\n        if not M:\n
```\nclass Solution(object):\n    def findCircleNum(self, M):\n        """\n        :type M: List[List[int]]\n        :rtype: int\n        """\n        if not M:\n            return 0\n\n        visited = set()\n        counter, n = 0, len(M)\n        for i in xrange(n):\n            if i not in visited:\n                self.dfs(M, i, visited)\n                counter += 1\n        return counter\n\n    def dfs(self, M, i, visited):\n        visited.add(i)\n        for idx, val in enumerate(M[i]):\n            if val == 1 and idx not in visited:\n                self.dfs(M, idx, visited)\n```
[]