Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- TreeNode* insertIntoBST(TreeNode* root, int val) {
- if (root == nullptr) return new TreeNode(val);
- if (val < root->val) {
- root->left = insertIntoBST(root->left, val);
- } else {
- root->right = insertIntoBST(root->right, val);
- }
- return root;
- }
- };
Add Comment
Please, Sign In to add comment