原题链接:计算布尔二叉树的值
mycode:
class Solution {
public:
bool evaluateTree(TreeNode* root) {
if(root->left==nullptr)
{
if(root->val==0)
return false;
else
return true;
}
else
{
bool left = evaluateTree(root->left);
bool right = evaluateTree(root->right);
if(root->val==2)
return left||right;
else
return left&&right;
}
}
};