Skip to content

Instantly share code, notes, and snippets.

@JunJaBoy
Created April 25, 2024 02:36
Show Gist options
  • Save JunJaBoy/ca0e74cbf88be2a6b0a4cb86a8fdb151 to your computer and use it in GitHub Desktop.
Save JunJaBoy/ca0e74cbf88be2a6b0a4cb86a8fdb151 to your computer and use it in GitHub Desktop.
HackerRank/Algorithm/LonelyInteger kotlin
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