力扣669、修剪二叉搜索树


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;
    }

}

文章作者: Axieyun
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Axieyun !
评论
评论
  目录