Created
December 20, 2022 20:22
-
-
Save cschlyter/3556d9ba34e5c9eb535f3b0388d01a7a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def findCircleNum(self, isConnected: List[List[int]]) -> int: | |
count = 0 | |
length = len(isConnected) | |
for i in range(length): | |
if isConnected[i][i] == 1: | |
count += 1 | |
self.dfs(i, length, isConnected) | |
return count | |
def dfs(self, i, length, matrix): | |
if matrix[i][i] == 0: | |
return | |
for j in range(length): | |
if matrix[i][j] == 1: | |
matrix[i][j] = 0 | |
self.dfs(j, length, matrix) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment