List SumByFoldLeft
object Sum { def sum(as: List[Int]): Int = FoldLeft.foldLeft(as, 0)(_ + _) def main(args: Array[String]): Unit = { println(sum(Nil)) println(sum(List(2))) println(sum(List(1, 2, 3, 4, 5))) } }
0 2 15
posted on 2016-04-19 22:11 JonkeyGuan 阅读(120) 评论(0) 收藏 举报
浙公网安备 33010602011771号