二叉树的最小深度

2018-01-06  本文已影响0人  第六象限
  public int minDepth(TreeNode root) {
        if(null == root) return 0;
        if(null == root.left) return minDepth(root.right) + 1;
        if(null == root.right) return minDepth(root.left) + 1;
        return Math.min(minDepth(root.left),minDepth(root.right)) + 1;
    }
上一篇 下一篇

猜你喜欢

热点阅读