mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-11 13:00:22 +08:00
Update 0669.修剪二叉搜索树,添加C#
This commit is contained in:
@ -567,6 +567,23 @@ impl Solution {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
### C#
|
||||||
|
```C#
|
||||||
|
// 递归
|
||||||
|
public TreeNode TrimBST(TreeNode root, int low, int high)
|
||||||
|
{
|
||||||
|
if (root == null) return null;
|
||||||
|
if (root.val < low)
|
||||||
|
return TrimBST(root.right, low, high);
|
||||||
|
|
||||||
|
if (root.val > high)
|
||||||
|
return TrimBST(root.left, low, high);
|
||||||
|
|
||||||
|
root.left = TrimBST(root.left, low, high);
|
||||||
|
root.right = TrimBST(root.right, low, high);
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
|
Reference in New Issue
Block a user