Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def pascal(c: Int, r: Int): Int = {
- if (c == 0 || c == r) 1 else (pascal(c - 1, r - 1) + pascal(c, r - 1))
- }
- def balance(chars: List[Char]): Boolean = {
- def balance_helper(chars: List[Char], total: Int): Boolean = {
- if (total < 0) {
- return false
- }
- chars match {
- case List() => (total == 0)
- case '(' :: rest => balance_helper(rest, total + 1)
- case ')' :: rest => balance_helper(rest, total - 1)
- case _ :: rest => balance_helper(rest, total)
- }
- }
- return balance_helper(chars, 0)
- }
Add Comment
Please, Sign In to add comment