【发布时间】:2016-05-04 07:13:44
【问题描述】:
我有一个递归方法,它应该从给定列表中删除所有零。
def removeZ(list:List[Int], n:Int):List[Int] = list match {
case Nil => Nil
case h::t=>
if (h == n)
t
else
h :: removeZ(t,n)
}
这会从列表中删除一个零,但如果列表中有多个零,则不会。我尝试添加另一个不起作用的 if else 语句,例如:
if else(t==n)
removeZ(t,n)
如何删除所有零?
【问题讨论】: