arnab
12/02/2016, 7:40 PMmutableList
of counts and then picks the first one by `count > 1`:
fun <E> List<E>.findFirstDuplicate(): E? {
val counts = mutableMapOf<E, Int>()
this.forEach {
if (counts.containsKey(it))
counts.put(it, counts[it]!! + 1)
else
counts.put(it, 1)
}
return this.find { counts[it]!! > 1 }
}