Python Solution

  • 0
    class Solution(object):
        def trimBST(self, root, L, R):
            if not root:
                return None
            if L <= root.val <= R:
                root.left = self.trimBST(root.left, L, R)
                root.right = self.trimBST(root.right, L, R)
                return root
            testNode = root.left if root.val > R else root.right
            return self.trimBST(testNode, L, R)

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.