class Solution {
public int minDepth(TreeNode root) {
if(null == root){
return 0;
}
if(null == root.left && null == root.right){
return 1;
}
if(null == root.left){
return minDepth(root.right)+1;
}
if(null == root.right){
return minDepth(root.left)+1;
}
int left = minDepth(root.left);;
int right = minDepth(root.right);
return Math.min(left,right)+1;
}
}
给定一个二叉树,找出其最小深度
最新推荐文章于 2023-02-21 10:00:59 发布