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