Skip to content

Commit 20843e6

Browse files
authored
Add files via upload
1 parent 530b927 commit 20843e6

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* struct TreeNode {
4+
* int val;
5+
* TreeNode *left;
6+
* TreeNode *right;
7+
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
8+
* };
9+
*/
10+
class Solution {
11+
public:
12+
TreeNode* insertIntoBST(TreeNode* root, int val) {
13+
if(!root){
14+
TreeNode* n = new TreeNode(val);
15+
return n;
16+
}
17+
18+
19+
if(root->val > val)
20+
root->left=insertIntoBST(root->left,val);
21+
else
22+
root->right=insertIntoBST(root->right,val);
23+
24+
return root;
25+
}
26+
};

0 commit comments

Comments
 (0)