leetCode练习题

1.求二叉树的最小深度:

public class Solution {
    public int run(TreeNode root) {
        if(root==null)
            return 0;
        int l = run(root.left);
        int r = run(root.right);
        if(l==0 || r==0)
            return l+r+1;
        return Math.min(l,r)+1;
    }
}
class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
}

 

posted @ 2018-03-09 15:06  如果屈原会编程  阅读(99)  评论(0)    收藏  举报