添加 0669.修剪二叉搜索树.md Scala版本
This commit is contained in:
@@ -453,7 +453,21 @@ function trimBST(root: TreeNode | null, low: number, high: number): TreeNode | n
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Scala
|
||||||
|
|
||||||
|
递归法:
|
||||||
|
```scala
|
||||||
|
object Solution {
|
||||||
|
def trimBST(root: TreeNode, low: Int, high: Int): TreeNode = {
|
||||||
|
if (root == null) return null
|
||||||
|
if (root.value < low) return trimBST(root.right, low, high)
|
||||||
|
if (root.value > high) return trimBST(root.left, low, high)
|
||||||
|
root.left = trimBST(root.left, low, high)
|
||||||
|
root.right = trimBST(root.right, low, high)
|
||||||
|
root
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user