grandyang / blogs

This repo is to hold the Gitalk comments for my blogs.
1 stars 0 forks source link

998. Maximum Binary Tree II | Grandyang's Blogs #1

Open grandyang opened 3 years ago

grandyang commented 3 years ago

https://grandyang.com/leetcode/998/

  1. Maximum Binary Tree II | Grandyang's Blogs
jyj407 commented 1 week ago

膜拜大佬!

jyj407 commented 1 week ago

我的理解下面的对称写法也是正确的,只是leetcode好像不接受这个解答。看题目要求并没有区分左右子树啊,只有根比左右子树都大就行。能请教大佬为什么吗? class Solution1 { public: TreeNode insertIntoMaxTree(TreeNode root, int val) { if (root && root->val > val) { root->right = insertIntoMaxTree(root->right, val); return root; }

    return new TreeNode(val, root, nullptr);
}

};

https://leetcode.cn/problems/maximum-binary-tree-ii/solutions/2957448/zong-shi-duo-jie-fa-998-zui-da-er-cha-sh-lo3k/