0998.cpp (414B)
1 class Solution { 2 public: 3 TreeNode *insertIntoMaxTree(TreeNode *root, int val) { 4 TreeNode *node = new TreeNode(val), *cur = root; 5 if (root->val < val) { 6 node->left = root; 7 return node; 8 } 9 10 while (cur->right && cur->right->val > val) 11 cur = cur->right; 12 13 node->left = cur->right; 14 cur->right = node; 15 return root; 16 } 17 };