Skip to content

Instantly share code, notes, and snippets.

@kghost
Created October 20, 2013 03:38
Show Gist options
  • Save kghost/7064763 to your computer and use it in GitHub Desktop.
Save kghost/7064763 to your computer and use it in GitHub Desktop.
case class BinaryTree(left: BinaryTree, right: BinaryTree)
def isFull(tree: BinaryTree): Boolean = {
def FullWithHeight(tree: BinaryTree): Int = {
if (tree == null) 0 else {
val l = FullWithHeight(tree.left)
val r = FullWithHeight(tree.right)
if (l >= 0 && l == r) l+1 else -1
}
}
FullWithHeight(tree) >= 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment