class Solution(object):
def trimBST(self, root, L, R):
"""
:type root: TreeNode
:type L: int
:type R: int
:rtype: TreeNode
"""
if root is None:
return None
data =root.val
if data<L or data>R:
a=self.trimBST(root.left,L,R)
b= self.trimBST(root.right,L,R)
return a if b is None else b
root.left=self.trimBST(root.left, L, R)
root.right=self.trimBST(root.right, L, R)
return root
leetcode 669. 修剪二叉搜索树
最新推荐文章于 2022-10-17 15:31:42 发布