class Solution {
public:
    TreeNode* pruneTree(TreeNode* root) {
        if(root==NULL)
        {
            return nullptr;
        }
        if(root->left!=NULL)
        {
            root->left = pruneTree(root->left);
        }
        if(root->right!=NULL)
        {
            root->right = pruneTree(root->right);
        }
        if(root->left==NULL&&root->right==NULL&&root->val==0)
        {
            return NULL;
        }
        return root;
    }
};

 

posted on 2018-10-10 14:11  Sempron2800+  阅读(110)  评论(0编辑  收藏  举报