This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parenthesis(input: List[Char], count: Int):Boolean ={ | |
input match { | |
case Nil if count==0 => true | |
case Nil if count!=0 => false | |
case head :: tail if count==(-1) => false | |
case head :: tail if head == '('=> parenthesis(tail, count + 1) | |
case head :: tail if head == ')'=> parenthesis(tail, count - 1) | |
case head :: tail if head!='(' && head!=')' => parenthesis(tail, count) | |
} | |
} |