easy java


  • 3
        public TreeNode trimBST(TreeNode root, int L, int R) {
            if (root == null) return null;
            TreeNode left = trimBST(root.left, L, R);
            TreeNode right = trimBST(root.right, L, R);
            root.left = left;
            root.right = right;
            return root.val >= L && root.val <= R? root : root.val < L? right : left; 
        }
    

Log in to reply
 

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