Skip to content

Instantly share code, notes, and snippets.

@yangbajing
Created August 3, 2012 08:27
Show Gist options
  • Save yangbajing/3245847 to your computer and use it in GitHub Desktop.
Save yangbajing/3245847 to your computer and use it in GitHub Desktop.
实例二: 找出数组中出现次数最多, 且数字最大的数, 返回该数字和出现的次数
scala> Array(1, 6, 6, 4, 5, 6).groupBy(x => x).maxBy{ case (key, group) => group.size -> key }
res5: (Int, Array[Int]) = (6,Array(6, 6, 6))
scala> Array(1, 6, 6, 4, 5, 5, 6, 5).groupBy(x => x).maxBy{ case (key, group) => group.size -> key }
res6: (Int, Array[Int]) = (6,Array(6, 6, 6))
scala> Array(1, 6, 6, 4, 5, 5, 6, 5).groupBy(x => x).maxBy{ case (key, group) => group.size }
res7: (Int, Array[Int]) = (5,Array(5, 5, 5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment