Created
April 25, 2024 02:36
-
-
Save JunJaBoy/ca0e74cbf88be2a6b0a4cb86a8fdb151 to your computer and use it in GitHub Desktop.
HackerRank/Algorithm/LonelyInteger kotlin
This file contains hidden or 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
import kotlin.* | |
fun lonelyinteger(a: Array<Int>): Int = | |
a.groupingBy { it } | |
.eachCount() | |
.filterValues { it == 1 } | |
.entries | |
.single() | |
.key | |
fun main(args: Array<String>) { | |
val n = readln().trim().toInt() | |
val a = readln().trimEnd() | |
.split(" ") | |
.map(String::toInt) | |
.toTypedArray() | |
val result = lonelyinteger(a) | |
println(result) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment