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