Created
July 1, 2014 08:18
-
-
Save weidagang/a4652196a1f0cbc33ebb to your computer and use it in GitHub Desktop.
HackerRank: List Length
This file contains 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
package list.length | |
object Main { | |
def f(arr: List[Int]): Int = arr match { | |
case x :: xs => 1 + f(xs) | |
case _ => 0 | |
} | |
def main(args: Array[String]) { | |
val len = f(List(1, 2, 3)); | |
println(len); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment