Advertisement
MiroJoseph

Find The Parity Outlier

Apr 9th, 2020
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.34 KB | None | 0 0
  1. My:
  2. object Parity {
  3.  
  4. def findOutlier(integers: List[Int]): Int =
  5.   if(integers.filter(x=>x%2==0).length>=2)
  6.         integers.filter(x => x % 2 != 0).head
  7.   else
  8.     integers.filter(x=>x%2==0).head
  9. }
  10.  
  11. Other:
  12. object Parity {
  13.   def findOutlier(integers: List[Int]): Int =
  14.     integers.groupBy(x => (x % 2).abs).minBy(_._2.length)._2.last
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement