814. 二叉树剪枝
有一点疑问,为什么不能先 if(!root->left&&!root->right&&root->val==0) return nullptr; ?
class Solution { public: TreeNode* pruneTree(TreeNode* root) { if(root==nullptr) return nullptr; root->left=pruneTree(root->left); root->right=pruneTree(root->right); if(!root->left&&!root->right&&root->val==0) return nullptr; return root; } };
标签:剪枝,right,return,nullptr,leetcode814,二叉树,&&,root,left From: https://www.cnblogs.com/uacs2024/p/16915216.html