로딩
요청 처리 중입니다...

[swift] 프로그래머스 네트워크

 [swift] 프로그래머스 네트워크

import foundation func solution(_ n:Int, _ computers:[[Int]]) -> Int { var length = computers.count // same as n var result = 0 var isVisited = Array(repeating: false, count: length) for i in 0 ..< length { if (isVisited[i] == false) { result += 1 dfs(i, &isVisited, computers) } } return result } private func dfs(_ index: Int, _ visitedArray: inout [Bool], _ computers: [[Int]] ) { visitedArray[index] = true for i in 0 ..< computers.count { if visitedArray[i] == false && computers[index][i] == 1{...