一、669. 修剪二叉搜索树
1.1、题目描述
class Solution:
def trimBST(self
, root
: TreeNode
, L
: int, R
: int) -> TreeNode
:
if not root
:
return root
if root
.val
< L
:
return self
.trimBST
(root
.right
, L
, R
)
elif root
.val
> R
:
return self
.trimBST
(root
.left
, L
, R
)
root
.left
= self
.trimBST
(root
.left
, L
, R
)
root
.right
= self
.trimBST
(root
.right
, L
, R
)
return root
转载请注明原文地址: https://mac.8miu.com/read-508239.html