Guest User

Untitled

a guest
Dec 12th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.58 KB | None | 0 0
  1.   def pascal(c: Int, r: Int): Int = {
  2.     if (c == 0 || c == r) 1 else (pascal(c - 1, r - 1) + pascal(c, r - 1))
  3.   }
  4.  
  5.   def balance(chars: List[Char]): Boolean = {
  6.     def balance_helper(chars: List[Char], total: Int): Boolean = {
  7.       if (total < 0) {
  8.         return false
  9.       }
  10.      
  11.       chars match {
  12.         case List() => (total == 0)
  13.         case '(' :: rest => balance_helper(rest, total + 1)
  14.         case ')' :: rest => balance_helper(rest, total - 1)
  15.         case _ :: rest => balance_helper(rest, total)
  16.       }
  17.     }
  18.     return balance_helper(chars, 0)
  19.   }
Add Comment
Please, Sign In to add comment