You are viewing a single comment's thread. Return to all comments →
Scala solution. Functional and simple
def f(arr:List[Int]):Int = if (arr == List()) 0 else if (arr.tail == List()) 1 else 1 + f(arr.tail)
List Length
You are viewing a single comment's thread. Return to all comments →
Scala solution. Functional and simple
def f(arr:List[Int]):Int = if (arr == List()) 0 else if (arr.tail == List()) 1 else 1 + f(arr.tail)