求树的最小深度
递归的思想:
递归出口; if(root==null)return 0;
if(root.left==null&&root.right==null){
return 1;
}
递; int left=run(root.left);遍历左子树;
int right=run(root.right);遍历右子树
归; if(left==0||right==0)return right+left+1;
return Math.min(left,right)+1;
public int run(TreeNode root) {
if(root==null)return 0;
if(root.left==null&&root.right==null){
return 1;
}
int left=run(root.left);
int right=run(root.right);
if(left==0||right==0)return right+left+1;
return Math.min(left,right)+1;
}