struct TreeNode* trimBST(struct TreeNode* root, int low, int high){
if (root == NULL) return NULL;
if (root->val < low) {
return trimBST(root->right, low, high);
} else if (root->val > high) return trimBST(root->left, low, high);
else {
root->left = trimBST(root->left, low, high);
root->right = trimBST(root->right, low, high);
return root;
}
}
上一篇
力扣题解450、删除二叉搜索树中的节点
2021-08-05
下一篇
力扣剑指Offer54、二叉搜索树的第k大节点
2021-08-05