728x90
반응형
Solution
- use recursive structure
Tag
- Full binary tree
class Solution {
public:
bool evaluateTree(TreeNode* root) {
bool retval = true;
if (root->left != nullptr && root->left != nullptr) // full binary tree
{
if (root->val == 2) // OR
{
retval = evaluateTree(root->left) || evaluateTree(root->right);;
}
else // operta = 3, AND
{
retval = evaluateTree(root->left) && evaluateTree(root->right);;
}
}
else
{
retval = root->val;
}
return retval;
}
};728x90
반응형
'코딩 문제' 카테고리의 다른 글
| [LeetCode] 2032. Two Out of Three, C++ (1) | 2023.01.25 |
|---|---|
| [Leet Code] 231. Power of Two, C++ (0) | 2023.01.17 |
| [LeetCode] 1880. Check if Word Equals Summation of Two Words, C (0) | 2023.01.05 |
| [LeetCode] 2406. Divide Intervals Into Minimum Number of Groups, C (0) | 2023.01.02 |
| [LeetCode] 1614. Maximum Nesting Depth of the Parenthesesm, C (1) | 2023.01.01 |