Evaluate Boolean Binary Tree (Leetcode 2331)
Problem Link: https://leetcode.com/problems/evaluate-boolean-binary-tree/
class Solution:
def evaluateTree(self, root: Optional[TreeNode]) -> bool:
def fun(root):
if(root.left is None and root.right is None):
if(root.val==0):
return False
else:
return True
l=fun(root.left)
r=fun(root.right)
if(root.val==2):
return l or r
else:
return l and r
return fun(root)
Last updated