Lonely Integer

  • + 0 comments

    Scala code:

    def lonelyinteger(a: Array[Int]): Int = {
         val distinctElements = a.distinct
         val repeatElements = a.diff(distinctElements)
         val uniqueInteger = (distinctElements diff repeatElements)(0)
         uniqueInteger
        }