Skip to content

Commit e1b562c

Browse files
authored
add java solution for Problem 701 (doocs#205)
Merged doocs#205
1 parent 03026d6 commit e1b562c

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* public class TreeNode {
4+
* int val;
5+
* TreeNode left;
6+
* TreeNode right;
7+
* TreeNode(int x) { val = x; }
8+
* }
9+
*/
10+
class Solution {
11+
public TreeNode insertIntoBST(TreeNode root, int val) {
12+
13+
if(root == null){
14+
root = new TreeNode(val);
15+
}
16+
17+
if(val < root.val){
18+
root.left = insertIntoBST(root.left, val);
19+
}
20+
else if(val > root.val){
21+
root.right = insertIntoBST(root.right, val);
22+
}
23+
24+
// return the unchanged pointer
25+
return root;
26+
}
27+
}

solution/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,7 @@
999999
├── 0701.Insert into a Binary Search Tree
10001000
│   ├── README.md
10011001
│   └── Solution.py
1002+
│   └── Solution.java
10021003
├── 0703.Kth Largest Element in a Stream
10031004
│   ├── README.md
10041005
│   └── Solution.java

0 commit comments

Comments
 (0)