Advertisement
MiroJoseph

FindTheOddInt

Apr 4th, 2020
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.25 KB | None | 0 0
  1. My:
  2. object FindTheOddInt {
  3.   def findOdd(xs: Seq[Int], index:Int=0): Int = {
  4.     if(xs.count(x=>x==xs(index))%2==0) findOdd(xs, index+1)
  5.     else xs(index)
  6.   }
  7. }
  8.  
  9. Other:
  10. object FindTheOddInt {
  11.   def findOdd(xs: Seq[Int]): Int = xs.reduce(_ ^ _)
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement