问题描述
解题思路
递归
代码
class Solution {
public:
bool dfs(TreeNode *root) {
if (root->left == nullptr) {
return root->val;
}
if (root-> val == 2) {
return dfs(root->left) || dfs(root->right);
} else {
return dfs(root->left) && dfs(root->right);
}
}
bool evaluateTree(TreeNode* root) {
return dfs(root);
}
};
标签:binary,return,2331,dfs,二叉树,root,left
From: https://www.cnblogs.com/zwyyy456/p/17095863.html