📅  最后修改于: 2022-03-11 14:57:48.283000             🧑  作者: Mango
fun main() {
val colors = arrayOf(10, 20, 20, 10, 10, 30, 50, 10, 20)
var pairs = 0
val colorFrequencies: MutableMap = mutableMapOf()
colors.forEach { color ->
val count = colorFrequencies.getOrDefault(color, 0)
colorFrequencies[color] = count+1
}
colorFrequencies.forEach { entry ->
pairs += entry.value / 2
}
println(pairs)
}