Maximum Depth of Binary Tree
EasyTrees
Find the maximum depth of a binary tree (the number of nodes along the longest path from the root to the farthest leaf node).
The tree is represented as a nested object: { val: 3, left: { val: 9, left: null, right: null }, right: { val: 20, left: null, right: null } }
Example:
Input: root = [3,9,20,null,null,15,7]
3
/ \
9 20
/ \
15 7
Output: 3
Constraints:
- •
0 <= number of nodes <= 10^4 - •
-100 <= Node.val <= 100
Maximum Depth of Binary Tree
EasyTrees
Find the maximum depth of a binary tree (the number of nodes along the longest path from the root to the farthest leaf node).
The tree is represented as a nested object: { val: 3, left: { val: 9, left: null, right: null }, right: { val: 20, left: null, right: null } }
Example:
Input: root = [3,9,20,null,null,15,7]
3
/ \
9 20
/ \
15 7
Output: 3
Constraints:
- •
0 <= number of nodes <= 10^4 - •
-100 <= Node.val <= 100
Press Run or Ctrl+Enter to execute