0

我在代码的最后一行有类型不匹配

 def balance(chars: List[Char]): Boolean = {

 def f(chars: List[Char], count: Int) :Boolean= 
  if(chars.isEmpty) {(count==0)}

      else if (chars.head == '(') f(chars.tail,count+1)
      else if(chars.head == ')') f(chars.tail,count-1)
      else f(chars.tail,count) 

 }  //Type mismatch; found: unit required Boolean
4

1 回答 1

1

balance期望Boolean作为返回值,但您只fbalance. 缺少的可能f(chars, 0)balance.

于 2013-09-21T15:35:16.237 回答