# Leetcode 701. Insert into a Binary Search Tree

`Input: root = [4,2,7,1,3], val = 5Output: [4,2,7,1,3,5]Explanation: Another accepted tree is:`
`Input: root = [40,20,60,10,30,50,70], val = 25Output: [40,20,60,10,30,50,70,null,null,25]`
`Input: root = [4,2,7,1,3,null,null,null,null,null,null], val = 5Output: [4,2,7,1,3,5]`
• The number of nodes in the tree will be in the range `[0, 104]`.
• `-108 <= Node.val <= 108`
• All the values `Node.val` are unique.
• `-108 <= val <= 108`
• It’s guaranteed that `val` does not exist in the original BST.
1. it’s a BST, if the value large than current node -> right side of tree; smaller than current node -> left side of tree
2. create a current node to be a pointer, and return the root at the end of the answer

--

--

## More from Gary Chiang

CS new grad, 6 years experience related to supply chain management. Located in Bay area

Love podcasts or audiobooks? Learn on the go with our new app.

## Gary Chiang

CS new grad, 6 years experience related to supply chain management. Located in Bay area