Skip to content

Commit 70493f7

Browse files
authored
Merge pull request #893 from LeoColman/KTLN-666-bfs
[KTLN-666] Optimize visited nodes on BFS
2 parents 925c2d4 + b32af38 commit 70493f7

File tree

1 file changed

+2
-2
lines changed
  • core-kotlin-modules/core-kotlin-10/src/main/kotlin/com/baeldung/bfs

1 file changed

+2
-2
lines changed

core-kotlin-modules/core-kotlin-10/src/main/kotlin/com/baeldung/bfs/Bfs.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.baeldung.bfs
22

3-
fun bfs(graph: Map<Int, List<Int>>, start: Int): List<Int> {
4-
val visited = mutableListOf<Int>()
3+
fun bfs(graph: Map<Int, List<Int>>, start: Int): Set<Int> {
4+
val visited = mutableSetOf<Int>()
55
val queue = ArrayDeque<Int>()
66
queue.add(start)
77
while (queue.isNotEmpty()) {

0 commit comments

Comments
 (0)