href="http://ounix1xcw.bkt.clouddn.com/github.markdown.css" rel="stylesheet">
这是leetcode的第669题--Trim a Binary Search Tree
题目 Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements lies in [L, R] (R >= L). You might need to change the root of the tree, so the result should return the new root of the trimmed binary search tree. 思路
show me the code
class Solution: def trimBST(self, root, L, R): """ :type root: TreeNode :type L: int :type R: int :rtype: TreeNode """ if not root:return None if L>root.val: return self.trimBST(root.right,L,R) elif R<root.val: 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
6536



被折叠的 条评论
为什么被折叠?



