diff --git a/kt/find-champion-ii.kt b/kt/find-champion-ii.kt new file mode 100644 index 0000000..43065e8 --- /dev/null +++ b/kt/find-champion-ii.kt @@ -0,0 +1,21 @@ +class Solution { + fun findChampion( + n: Int, + edges: Array, + ): Int { + val degrees = IntArray(n) + for (edge in edges) { + degrees[edge[1]] += 1 + } + + val candidates = + degrees.withIndex().filter { + it.value == 0 + }.take(2) + + return when { + candidates.size == 1 -> candidates.first().index + else -> -1 + } + } +}