Leetcode 111. Minimum Depth of Binary Tree

来源:互联网 发布:淘宝卖家物流费用标准 编辑:程序博客网 时间:2024/06/13 02:14
public class Solution {    public int minDepth(TreeNode root) {        if (root == null) return 0;        // take care of the trees that only have left or right child        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;    }}

0 0