Skip to content

Commit d4932a4

Browse files
committed
998. Maximum Binary Tree II
1 parent 4f2be83 commit d4932a4

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

maximum-binary-tree-ii.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//Runtime: 8 ms
2+
//Memory Usage: 11.7 MB
3+
class Solution {
4+
public:
5+
TreeNode* insertIntoMaxTree(TreeNode* root, int val) {
6+
if (!root) return new TreeNode(val);
7+
if (root->val < val) {
8+
TreeNode* node = new TreeNode(val);
9+
node->left = root;
10+
return node;
11+
}
12+
root->right = insertIntoMaxTree(root->right, val);
13+
return root;
14+
}
15+
};

0 commit comments

Comments
 (0)