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