My Blog List

[Leetcode Solution] Minimum Depth of Binary Tree

Analysis

  • Using BFS search each layer of binary tree from the root to leaf. 
  • Check nodes in each layer. If some node has no child then that is the leaf in the minimum path to the root
  • In practical using two vector alternatively to store the current and next layer of the tree when searching

Note

Code


No comments:

Post a Comment

Enter you comment