零基础平面设计教程,上海网站seo公司,wordpress 注册插件,医疗室内设计网站推荐1. 题目
向最大二叉树插入一个值#xff1b; 如果该值大于根节点#xff0c;则子树必须在该值的左边#xff1b; 如果该值小于根节点#xff0c;则该值必须在根节点的右子树
2. 解题 class Solution {
public:TreeNode* insertIntoMaxTree(TreeNode* root, int val) {if(…1. 题目
向最大二叉树插入一个值 如果该值大于根节点则子树必须在该值的左边 如果该值小于根节点则该值必须在根节点的右子树
2. 解题 class Solution {
public:TreeNode* insertIntoMaxTree(TreeNode* root, int val) {if(root NULL)return new TreeNode(val);if(root-val val){TreeNode *newNode new TreeNode(val);newNode-left root;return newNode;}else{root-right insertIntoMaxTree(root-right, val);return root;}}
};