mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 20:40:39 +08:00
Update0701.二叉搜索树中的插入操作,添加C#
This commit is contained in:
@ -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">
|
||||||
|
Reference in New Issue
Block a user