Open grandyang opened 3 years 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://grandyang.com/leetcode/998/