class Solution:
def evaluateTree(self, root: Optional[TreeNode]) -> bool:
def travel(node):
if node:
leftVal = travel(node.left)
rightVal = travel(node.right)
return node.val if not node.left else (leftVal or rightVal) if node.val == 2 else (leftVal and rightVal)
return travel(root)