Leetcode每日一题2021/01/24

Leetcode每日一题2021/01/24_第1张图片
Leetcode每日一题2021/01/24_第2张图片
3

class Solution:
    def findCircleNum(self, isConnected: List[List[int]]) -> int:
        def DFS(i):
            for j in range(n):
                if(isConnected[i][j] and visited[j] == 0):
                    visited[i] = 1
                    DFS(j)
                    
        
        n, count = len(isConnected), 0
        visited = [0 for i in range(n)]		# 初始化记录数组,全部置0
        for i in range(n):
            if(visited[i] == 0):
                DFS(i)
                count += 1
        return count

Leetcode每日一题2021/01/24_第3张图片

你可能感兴趣的:(Leetcode,leetcode,dfs,算法,列表)