https://leetcode.com/problems/maximum-binary-tree-ii/
在654. Maximum Binary Tree版本的建树基础上,在最后插入一个数。
新节点要么为根节点,原树为其左子树;要么将新节点插在右子树中。
class Solution { public: TreeNode* insertIntoMaxTree(TreeNode* root, int val) { if(root == NULL) { root = new TreeNode(val); return root; } if(val > root->val) { TreeNode* temporary = root; root = new TreeNode(val); root->left = temporary; return root; } else { root->right = insertIntoMaxTree(root->right, val); return root; } } };