首页 > 技术文章 > LeetCode 二叉树的最小深度

googlemeoften 2016-08-29 13:53 原文

计算二叉树的最小深度。最小深度定义为从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;
    }
}  

 

推荐阅读