70-BFS/DFS/并查集–LC547省份数量
这个题相较于LC200更难一点,给的矩阵说的是两个城市是否相连,可以是直接相连也可以是间接相连。
class Solution(object):
def findCircleNum(self, isConnected):
"""
:type isConnected: List[List[int]]
:rtype: int
"""
# 1.DFS
row = len(isConnected)
visited = [0 for i in range(row)]
result = 0
for i in range(row):
if not visited[i]:
self.dfs(i, row, visited
共有 0 条评论