5.4.1 Minimum Depth of Binary Tree

Notes:
  Given a binary tree, find its minimum depth.
  The minimum depth is the number of nodes along the shortest path from the root node
  down to the nearest leaf node.
 
  Solution: 1. Recursion. Pay attention to cases when the non-leaf node has only one child.
  2. Iteration + Queue. Contributed by SUN Mian(孙冕).
  */
   
  /**
  * Definition for binary tree
  * struct TreeNode {
  * int val;
  * TreeNode *left;
  * TreeNode *right;
  * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
  * };
  */
int BiTree::minDepth(BiNode*root)
{
if (!root)
return 0;
return 1 + min(minDepth(root->lchild), minDepth(root->rchild));


}

你可能感兴趣的:(5.4.1 Minimum Depth of Binary Tree)