0
Leetcode Problem 104. Maximum Depth of Binary Tree
104. Maximum Depth of Binary Tree
AI Mock Interview
Leetcode Solutions
Approach: Recursion
Solution Idea
Algorithm Steps
Code Implementation
Complexity Analysis
Define a recursive function
maxDepth
that takes a
TreeNode
as its argument.
If the node is
null
, return 0.
Recursively call
maxDepth
on the left child and store the result.
Recursively call
maxDepth
on the right child and store the result.
Return the greater of the two stored results plus one.
Approach: Iterative with Queue (BFS)
Ask Question
Programming Language
Purpose:
General Question
Debug My Code
image/screenshot of info
(optional)
[+]
Full Screen
Loading...
Get Answer
Suggested Answer
Answer
Full Screen
Copy Answer Code
Loading...