DEV Community

Karleb
Karleb

Posted on

2331. Evaluate Boolean Binary Tree

https://leetcode.com/problems/evaluate-boolean-binary-tree/description/?envType=daily-question&envId=2024-05-16

var evaluateTree = function(root) {
    if (root === null) return false
    if (root.val === 0) return false
    if (root.val === 1) return true

    let left = evaluateTree(root.left)
    let right = evaluateTree(root.right)

    return root.val === 2 ? left || right : left && right
};

Enter fullscreen mode Exit fullscreen mode

Top comments (0)