题目:
分析:
深度优先遍历
代码:
class Solution {
int min=Integer.MAX_VALUE;
public int minDepth(TreeNode root) {
if(root==null)
return 0;
help(root,1);
return min;
}
public void help(TreeNode root,int depth){
if(root.left!=null){
help(root.left,depth+1);
}
if(root.right!=null){
help(root.right,depth+1);
}
if(root.left==null && root.right==null&& depth<min)
min=depth;
}
}