1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| class Solution { fun solution(numbers: IntArray): String { var answer = "" var tempArray = numbers.map { it.toString() }.toTypedArray() tempArray.sortWith(Comparator<String> { a, b -> when { a.length == b.length -> b.compareTo(a) else -> (b + a).compareTo(a + b) } }) if (tempArray[0] == "0") { answer = "0" return answer } tempArray.forEach { answer += it }
return answer } }
|