111. Minimum Depth of Binary Tree

    /*
     * 111. Minimum Depth of Binary Tree 
     * 2016-5-17 by Mingyang 还是用queue来做
     * 千万可不能小看这些题目,自己开始做的又错了
     */
     public int minDepth1(TreeNode root) {
            if(root==null)
              return 0;
            //最开始做的时候没有写这两个条件,还是属于基本功不扎实,连base case都写不好---------------------------
            if(root.left==null)
              return minDepth(root.right)+1;
            if(root.right==null)
              return minDepth(root.left)+1;
            //------------------------------------------------
            return Math.min(minDepth(root.left),minDepth(root.right))+1;
        }
     //网上的代码
    public int minDepth(TreeNode root) {
        if (root == null)
            return 0;
        int left = minDepth(root.left);
        int right = minDepth(root.right);
        return (left == 0 || right == 0) ? left + right + 1 : Math.min(left,right) + 1;
    }
原文地址:https://www.cnblogs.com/zmyvszk/p/5504728.html