1 2 3 4 5 6 7 8 9
| class Solution { fun solution(s: String): IntArray { return s.split("},{") .map { it.replace("[^0-9,]".toRegex(), "").split(",").map { it.toInt() } } .sortedBy { it.size } .fold(setOf<Int>()) { acc, list -> acc.union(list) } .toIntArray() } }
|