def movesToMakeZigzag(A: Array[Int]): Int = {
def f(i:Int):Int = {
A.indices.toList
.filter(_%2 == i)
.map{x =>
0 max (List(x-1, x+1) filter A.indices.contains map A map (y => A(x) - y + 1) max)}
.sum
}
f(0) min f(1)
}1.和Ruby类似,Scala中将最后出现的变量作为return的值。
2.https://www.cnblogs.com/fxjwind/p/3338829.html 富包装
3.https://docs.scala-lang.org/zh-cn/cheatsheets/index.html 下划线用法
4.https://www.zhihu.com/question/21622725
5 数组遍历 https://juejin.im/post/5d859398f265da03b9502f4c
https://blog.csdn.net/pan12jian/article/details/28645705 富包装