Ad
Code
Diff
  • treeHeight=$=_=>!_?0:Math.max($(_.left),$(_.right))+1
    • function treeHeight(node)
    • {
    • if (node == null)
    • return 0;
    • else
    • {
    • /* compute the height of each subtree */
    • var lheight = treeHeight(node.left);
    • var rheight = treeHeight(node.right);
    • /* use the larger one */
    • if (lheight > rheight)
    • {
    • return(lheight + 1);
    • }
    • else {
    • return(rheight + 1);
    • }
    • }
    • }
    • treeHeight=$=_=>!_?0:Math.max($(_.left),$(_.right))+1