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