We’re preparing your current view and syncing the latest data.
Given the root node of a Binary Search Tree (BST) and a value to insert into the tree, insert the value into the BST and return the root node of the BST after insertion. It is guaranteed that the new value does not exist in the original BST. The insertion must maintain the properties of the BST.
Return the root node of the BST after inserting the given value.
Example 1
Input
root = [4,2,7,1,3], val = 5
Output
[4,2,7,1,3,5]
Explanation
After inserting 5, the tree should maintain the BST property with 5 as the left child of 7.