EP669

作者: ShadowTuDark | 来源:发表于2019-05-20 23:38 被阅读0次

https://leetcode.com/problems/trim-a-binary-search-tree/

image.png
class Solution {
public:
    TreeNode* trimBST(TreeNode* root, int L, int R) {
        if (root == NULL) return NULL;
        if (root->val < L) return trimBST(root->right, L, R);
        if (root->val > R) return trimBST(root->left, L, R);
        root->left = trimBST(root->left, L, R);
        root->right = trimBST(root->right, L, R);
        return root;
    }
};

相关文章

  • EP669

    https://leetcode.com/problems/trim-a-binary-search-tree/

网友评论

      本文标题:EP669

      本文链接:https://www.haomeiwen.com/subject/elsrzqtx.html