Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- Developer
- intarray
- contentToString
- 2D Array
- indices
- Kotlin
- programmers
- sortedBy
- hackerrank
- Util
- dynamic programming
- solution
- 알고리즘
- heap
- foreach
- 동적계획법
- Java
- lastIndex
- PriorityQueue
- report
- Poll
- Recursion
- 2020
- Main
- dp
- booleanarray
- 코틀린
- GREEDY
- Queue
- 프로그래머스
Archives
- Today
- Total
Code in
프로그래머스 깊이/너비 우선 탐색 네트워크 with Kotlin 본문
프로그래머스 깊이/너비 우선 탐색 네트워크 문제입니다.

IntelliJ에서의 풀이입니다.
val n = 3
val computers = arrayOf(intArrayOf(1, 1, 0), intArrayOf(1, 1, 0), intArrayOf(0, 0, 1))
val computers2 = arrayOf(intArrayOf(1, 1, 0), intArrayOf(1, 1, 1), intArrayOf(0, 1, 1))
fun solution(n: Int, computers: Array<IntArray>): Int {
var answer = 0
val visited = Array<BooleanArray>(n) { BooleanArray(n){false} }
for (i in 0 until n){
if (!visited[i][i]){
network(computers, i, n, visited)
answer++
}
}
return answer
}
fun network(computers: Array<IntArray>, i: Int, n: Int, visited: Array<BooleanArray>){
for (j in 0 until n){
if (computers[i][j] == 1 && !visited[i][j]){
visited[i][j] = true
visited[j][i] = true
network(computers, j, n, visited)
}
}
}
fun main() {
//println(solution(n, computers)) //2
println(solution(n, computers2)) //1
}
URL: https://programmers.co.kr/learn/courses/30/lessons/43162
코딩테스트 연습 - 네트워크
네트워크란 컴퓨터 상호 간에 정보를 교환할 수 있도록 연결된 형태를 의미합니다. 예를 들어, 컴퓨터 A와 컴퓨터 B가 직접적으로 연결되어있고, 컴퓨터 B와 컴퓨터 C가 직접적으로 연결되어 있��
programmers.co.kr
'알고리즘 스터디_문제풀이' 카테고리의 다른 글
프로그래머스 깊이/너비 우선 탐색 여행경로 with Kotlin (0) | 2020.08.30 |
---|---|
프로그래머스 깊이/너비 우선 탐색 단어 변환 with Kotlin (1) | 2020.08.26 |
프로그래머스 깊이/너비 우선 탐색 타겟 넘버 with kotlin (1) | 2020.08.25 |
프로그래머스 동적계획법 N으로 표현 with Kotlin (2) | 2020.08.23 |
프로그래머스 탐욕법(Greedy) 섬 연결하기 with Kotlin (2) | 2020.08.18 |