码迷,mamicode.com
首页 > 其他好文 > 详细

Arrays.asList

时间:2020-08-08 17:38:29      阅读:62      评论:0      收藏:0      [点我收藏+]

标签:idt   except   arrays   exception   image   元素   报错   直接   code   

Leetcode 111 二叉树最小深度

给定一颗二叉树,求根节点到叶子节点的最短路径(最小深度)

class Solution{
    public int minDepth(TreeNode root){
        //若无根节点(空树),则返回0
        if(root==null) {
            return 0;
        }
        //叶子节点,向上返回1,递归结束
        else if(root!=null && root.left==null && root.right==null)
        else {
            //子树非空,继续向下搜索到根节点
            if(root.left!=null && root.right==null) {
                return 1 + minDepth(root.left);
            }
            else if(root.left==null && root.right!=null) {
                return 1 + minDepth(root.right);
            }
            else(root.left!=null && root.right!=null) {
                return 1 + Math.min(minDepth(root.left), minDepth(root.right));
            }
        }
    }
}

Arrays.asList

标签:idt   except   arrays   exception   image   元素   报错   直接   code   

原文地址:https://www.cnblogs.com/rempop/p/13457539.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!