Skip to content

Instantly share code, notes, and snippets.

@eakray
Last active February 1, 2016 01:48
Show Gist options
  • Select an option

  • Save eakray/a40fdcf5a566f5182885 to your computer and use it in GitHub Desktop.

Select an option

Save eakray/a40fdcf5a566f5182885 to your computer and use it in GitHub Desktop.
Tree height function
var getTreeHeight = function(tree) {
var counter = 1;
var max = 0;
var position = tree.root;
(function recurse(node){
if(!node){
return;
}
if(counter > max){
max = counter;
}
recurse(node.left);
recurse(node.right);
counter++;
})(position);
return max;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment