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. 修剪二叉搜索樹
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.