We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
💬 문제
https://school.programmers.co.kr/learn/courses/30/lessons/43162
💬 Idea
네트워크를 표현하는 연결 리스트 그래프를 먼저 만든 후, 0부터 시작하여 연결된 모든 노드를 탐색한다.
💬 풀이
func solution(n:Int, computers:[[Int]]) -> Int { var networkDict: [Int: [Int]] = [:] for (i, ci) in computers.enumerated() { if networkDict[i] == nil { networkDict[i] = [] } for (j, _) in ci.enumerated() { if computers[i][j] == 1 { networkDict[i]?.append(j) } } } return dfsToFindNetwork(networkDict, 0) } func dfsToFindNetwork(_ arr: [Int: [Int]], _ start: Int) -> Int { var arr = arr var networkCount = 0 var needVisitStack: [Int] = [start] var visitedQueue: [Int] = [] while !needVisitStack.isEmpty { let node = needVisitStack.removeLast() if visitedQueue.contains(node) { continue } visitedQueue.append(node) needVisitStack += arr[node] ?? [] if ((arr[node]?.isEmpty) != nil) { arr.removeValue(forKey: node) } } networkCount += 1 if arr.count > 0 { networkCount += dfsToFindNetwork(arr, arr.first!.key) } return networkCount }
The text was updated successfully, but these errors were encountered:
#163 - 네트워크 문제 풀이
9b444fd
hwangJi-dev
No branches or pull requests
💬 문제
https://school.programmers.co.kr/learn/courses/30/lessons/43162
💬 Idea
네트워크를 표현하는 연결 리스트 그래프를 먼저 만든 후, 0부터 시작하여 연결된 모든 노드를 탐색한다.
💬 풀이
The text was updated successfully, but these errors were encountered: