Skip to content

Commit ba4d0e2

Browse files
committed
Update readme.md
1 parent a952c7d commit ba4d0e2

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

insert-into-a-binary-search-tree/readme.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ https://leetcode.cn/problems/insert-into-a-binary-search-tree/
77
```java []
88
class Solution {
99
public TreeNode insertIntoBST(TreeNode root, int val) {
10-
10+
1111
if (root == null) // 如果当前节点为空,也就意味着val找到了合适的位置,此时创建节点直接返回。
1212
return new TreeNode(val);
1313
if (root.val < val){
@@ -31,12 +31,13 @@ class Solution {
3131
* var right: TreeNode? = null
3232
* }
3333
*/
34+
3435
class Solution {
3536
fun insertIntoBST(root: TreeNode?, `val`: Int): TreeNode? {
36-
if(root==null)return TreeNode(`val`)
37-
if(root.`val`>`val`)root.left=insertIntoBST(root.left,`val`)
38-
if(root.`val`<`val`)root.right=insertIntoBST(root.right,`val`)
39-
return root
37+
if (root == null) return TreeNode(`val`)
38+
if (root.`val` > `val`) root.left = insertIntoBST(root.left, `val`)
39+
if (root.`val` < `val`) root.right = insertIntoBST(root.right, `val`)
40+
return root
4041
}
4142
}
4243
```
@@ -57,11 +58,11 @@ return root
5758
*/
5859

5960
function insertIntoBST(root: TreeNode | null, val: number): TreeNode | null {
60-
if(root === null) return { val,left:null,right:null }
61-
if(root.val > val) root.left = insertIntoBST(root.left,val)
62-
else if(root.val < val) root.right = insertIntoBST(root.right,val);
61+
if (root === null) return { val, left: null, right: null };
62+
if (root.val > val) root.left = insertIntoBST(root.left, val);
63+
else if (root.val < val) root.right = insertIntoBST(root.right, val);
6364
return root;
64-
};
65+
}
6566
```
6667

6768
```go []
@@ -95,10 +96,10 @@ public:
9596
```
9697
9798
```php []
98-
class Solution
99+
class Solution
99100
{
100101
// 递归函数,返回构造后 BST 的根节点
101-
public function insertIntoBST($root, $val)
102+
public function insertIntoBST($root, $val)
102103
{
103104
if ($root === null) return new TreeNode($val);
104105
@@ -107,7 +108,7 @@ class Solution
107108
} else {
108109
$root->right = $this->insertIntoBST($root->right, $val);
109110
}
110-
111+
111112
return $root;
112113
}
113114
}
@@ -130,7 +131,7 @@ class Solution
130131
public class Solution {
131132
public TreeNode InsertIntoBST(TreeNode root, int val) {
132133

133-
134+
134135
if (root == null) // 如果当前节点为空,也就意味着val找到了合适的位置,此时创建节点直接返回。
135136
return new TreeNode(val);
136137
if (root.val < val){

0 commit comments

Comments
 (0)