0
点赞
收藏
分享

微信扫一扫

返回二叉树的子树

小编 2022-03-19 阅读 68

返回二叉树的子树

    public static TreeNode subTree(TreeNode root, int subNode) {
        if (root == null) return null;

        if (root.val == subNode) return root;

        TreeNode left = subTree(root.left, subNode);
        TreeNode right = subTree(root.right, subNode);

        return left == null ? right : left;
    }

二叉树其他代码在 二叉树建立 中!!!

举报

相关推荐

0 条评论