File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
0701.Insert into a Binary Search Tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 999
999
├── 0701.Insert into a Binary Search Tree
1000
1000
│ ├── README.md
1001
1001
│ └── Solution.py
1002
+ │ └── Solution.java
1002
1003
├── 0703.Kth Largest Element in a Stream
1003
1004
│ ├── README.md
1004
1005
│ └── Solution.java
You can’t perform that action at this time.
0 commit comments