首页 > 技术文章 > leetcode814

asenyang 2018-10-10 14:11 原文

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

 

推荐阅读