Update0701.二叉搜索树中的插入操作,添加C#
This commit is contained in:
parent
09e230bef3
commit
35322cb120
|
|
@ -691,6 +691,17 @@ impl Solution {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
### C#
|
||||||
|
``` C#
|
||||||
|
// 递归
|
||||||
|
public TreeNode InsertIntoBST(TreeNode root, int val) {
|
||||||
|
if (root == null) return new TreeNode(val);
|
||||||
|
|
||||||
|
if (root.val > val) root.left = InsertIntoBST(root.left, val);
|
||||||
|
if (root.val < val) root.right = InsertIntoBST(root.right, val);
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue