Leetcode Problem 111. Minimum Depth of Binary Tree

111. Minimum Depth of Binary Tree

Leetcode Solutions

Depth-First Search (DFS) Approach

  1. Define a recursive function dfs that takes a node as an argument.
  2. If the node is null, return 0.
  3. If one child is null, return the depth of the subtree with the non-null child plus 1.
  4. If both children are non-null, return 1 plus the minimum of the depths of the left and right subtrees.
  5. Call dfs with the root node and return its value.
UML Thumbnail

Breadth-First Search (BFS) Approach

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...