Created
July 30, 2019 01:01
-
-
Save cg4jins/2d7f40b93ff614f5d1fe82caf7ed31f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
fun solution(numbers: IntArray): String { | |
val sorted = numbers.sortedWith(Comparator { o1, o2 -> compare1(o1, o2) }) | |
if (sorted.stream().allMatch { it == 0 }){ | |
return "0" | |
} | |
return sorted.joinToString("") | |
} | |
private fun compare1(o1: Int, o2: Int): Int { | |
var s1 = o1.toString() | |
var s2 = o2.toString() | |
if (s1.length == s2.length) { | |
return o2 - o1 | |
} | |
var s1First : Int = "$s1$s2".toInt() | |
var s2First : Int = "$s2$s1".toInt() | |
return s2First - s1First | |
} | |
} | |
fun main() { | |
println(Solution().solution(intArrayOf(0, 0))) // 0 | |
println(Solution().solution(intArrayOf(0, 1000, 0, 0))) // 100000 | |
println(Solution().solution(intArrayOf(12, 121))) // 12121 | |
println(Solution().solution(intArrayOf(21, 212))) // 21221 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment