美文网首页
111. Minimum Depth of Binary Tre

111. Minimum Depth of Binary Tre

作者: 夜皇雪 | 来源:发表于2016-12-13 06:24 被阅读0次
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
public class Solution {
    public int minDepth(TreeNode root) {
        if(root==null) return 0;
        if(root.left==null||root.right==null)
            return Math.max(minDepth(root.left),minDepth(root.right))+1;
        return Math.min(minDepth(root.left),minDepth(root.right))+1;
    }
}

相关文章

网友评论

      本文标题:111. Minimum Depth of Binary Tre

      本文链接:https://www.haomeiwen.com/subject/cnuvmttx.html