Skip to content

Instantly share code, notes, and snippets.

@ttsugriy
Created January 23, 2019 01:39
Show Gist options
  • Save ttsugriy/4a24bdd0efd1957e5211d329fb7951e2 to your computer and use it in GitHub Desktop.
Save ttsugriy/4a24bdd0efd1957e5211d329fb7951e2 to your computer and use it in GitHub Desktop.
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;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment