bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 104. Maximum Depth of Binary Tree

104. Maximum Depth of Binary Tree

Leetcode Solutions

Approach: Recursion

  1. Define a recursive function maxDepth that takes a TreeNode as its argument.
  2. If the node is null, return 0.
  3. Recursively call maxDepth on the left child and store the result.
  4. Recursively call maxDepth on the right child and store the result.
  5. Return the greater of the two stored results plus one.
UML Thumbnail

Approach: Iterative with Queue (BFS)

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...