Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def balance(chars: List[Char]): Boolean = {
- def balanceInner(chars: List[Char], acc: Int = 0): Boolean = {
- def accUpgrade(character: Char) = character match {
- case '(' => acc + 1
- case ')' => acc + -1
- case _ => acc
- }
- if (acc < 0) false else chars.isEmpty match {
- case true => if (acc == 0) true else false
- case false => balanceInner(chars.tail, accUpgrade(chars.head))
- }
- }
- balanceInner(chars)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement