def balance(chars: List[Char]): Boolean = { if (chars.isEmpty == true) true else transCount(chars, 0) def transCount(chars: List[Char], pro: Int): Boolean = { var dif = pro chars match { case "(" :: Nil => false case ")" :: Nil => dif -= 1; if (dif == 0) true else false case _ :: Nil => if (dif == 0) true else false case "(" :: tail => dif += 1 transCount(tail, dif) case ")" :: tail => dif -= 1; if (dif < 0) false else transCount(tail, dif) case _ :: tail => transCount(tail, dif) } } } I have the type mismatch problem
Error:(30, 13) type mismatch; found : String("(") required: Char case "(" :: Nil => false ^ but really do not know how to fix (do not use char.toList please)
Charliterals use single quotes so you need to usecase '(' :: Nil => false ...instead.