Voici la fonction d'équilibrage des parenthèses dans scala. Je reçoisIncompatibilité de type dans Scala Code
Error:(36, 10) type mismatch; found : Unit required: Int a=a+1
var a = 0
def balance(chars: List[Char]): Boolean = {
if(chars.isEmpty)
return Nil
{
if (chars.head == ')')
a=a-1
else (chars.head == '(')
a=a+1
}
if (a == -1)
return false
if ((a == 1 || a == 0) && chars.tail.isEmpty!= 0)
balance(chars.tail)
if (a == 0 && chars.tail.isEmpty)
return true
}
Quelqu'un peut-il me dire pourquoi cette erreur vient?