Created
August 3, 2012 08:27
-
-
Save yangbajing/3245847 to your computer and use it in GitHub Desktop.
实例二: 找出数组中出现次数最多, 且数字最大的数, 返回该数字和出现的次数
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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