Skip to content

Commit 75bc4f1

Browse files
committed
701. 二叉搜索树中的插入操作
1 parent 140a912 commit 75bc4f1

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.gatsby;
2+
3+
/**
4+
* @ClassName: _701InsertIntoBinarySearchTree
5+
* @Description: leetcode 701 二叉搜索树中的插入操作
6+
* @author: Gatsby
7+
* @date: 2022/5/17 15:02
8+
*/
9+
10+
public class _701InsertIntoBinarySearchTree {
11+
public TreeNode insertIntoBST(TreeNode root, int val) {
12+
if (root == null) return new TreeNode(val);
13+
14+
if (val < root.val) {
15+
root.left = insertIntoBST(root.left, val);
16+
return root;
17+
} else {
18+
root.right = insertIntoBST(root.right, val);
19+
return root;
20+
}
21+
}
22+
}
23+
24+

0 commit comments

Comments
 (0)