Skip to content

Instantly share code, notes, and snippets.

@tyano
Created December 4, 2011 04:54
Show Gist options
  • Save tyano/1429218 to your computer and use it in GitHub Desktop.
Save tyano/1429218 to your computer and use it in GitHub Desktop.
List(1, 2, 3, 1) を Map(1 -> 2, 2 -> 1, 3 -> 1) No.2
List(1,2,3,1).foldLeft(Map[Int,Int]()) { (x, y) => x.get(y) match { case Some(v) => x + Pair(y, (v + 1)) case None => x + Pair(y, 1) }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment