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;
}

 

相关文章:

  • 2021-06-07
  • 2021-06-29
  • 2021-12-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-09
  • 2022-12-23
  • 2021-12-06
  • 2021-10-04
  • 2021-06-09
  • 2021-12-04
  • 2022-12-23
相关资源
相似解决方案