> For the complete documentation index, see [llms.txt](https://wentao-shao.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wentao-shao.gitbook.io/leetcode/divide-conquer/insert-node-in-a-binary-search-tree.md).

# Insert Node In A Binary Search Tree

## Insert Node In A Binary Search Tree

## 题目地址

<https://www.lintcode.com/problem/insert-node-in-a-binary-search-tree/description>

<https://www.jiuzhang.com/solution/insert-node-in-a-binary-search-tree/>

## 题目描述

```
Given a binary search tree and a new tree node, insert the node into the tree. You should keep the tree still be a valid binary search tree.
```

## 代码

### Approach #1 Recursion

```java
public class Solution {
    public TreeNode insertNode(TreeNode root, TreeNode node) {
    if (root == null) return node;

    if (root.val > node.val) {
      root.left = insertNode(root.left, node);
    } else {
      root.right = insertNode(root.right, node);
    }

    return root;
  }

}
```
