Python Easiest Solution


  • 0
    K
    class Solution(object):
        def trimBST(self, root, L, R):
            if not root:
                return None
            
            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
    

Log in to reply
 

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