Created
May 6, 2021 11:40
-
-
Save leonidkuznetsov18/6ba2a279691094e0407ed92675c0b937 to your computer and use it in GitHub Desktop.
binary tree height
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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