LeetCode 二叉树的最小深度

计算二叉树的最小深度。最小深度定义为从root到叶子节点的最小路径。

public class Solution {
    public int run(TreeNode root) {
        if(root == null) return 0;
        if(root.left == null)return run(root.right) + 1;
        if(root.right == null) return run(root.left) + 1;

        return Math.min(run(root.left), run(root.right)) + 1;
    }
}  

 

posted @ 2016-08-29 13:53  googlemeoften  阅读(219)  评论(0编辑  收藏  举报