Skip to content

Instantly share code, notes, and snippets.

@leonidkuznetsov18
Created May 6, 2021 11:40
Show Gist options
  • Select an option

  • Save leonidkuznetsov18/6ba2a279691094e0407ed92675c0b937 to your computer and use it in GitHub Desktop.

Select an option

Save leonidkuznetsov18/6ba2a279691094e0407ed92675c0b937 to your computer and use it in GitHub Desktop.
binary tree height
function TreeNode(val) {
this.val = val;
this.left = this.right = null;
}
/**
* @param {TreeNode} root
* @return {number}
*/
const maxDepth = root => {
if (!root) {
return 0;
}
return 1 + Math.max(maxDepth(root.left), maxDepth(root.right));
};
export default maxDepth;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment