Skip to content

Instantly share code, notes, and snippets.

@kghost
Created October 20, 2013 03:38
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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