FunctionRacerProblemsRace

Evaluate Boolean Binary Tree

EasyTreesPython, JavaScript, TypeScript, Java, C++

You are given the root of a binary tree. Leaves hold 0 (False) or 1 (True). Every other node has exactly two children and holds 2 (OR) or 3 (AND). A leaf evaluates to its own value as a boolean, and an internal node applies its operator to the results of its two children. Return the value of the root as a boolean.

Trees appear in the tests in level order, with null for a missing child, like [3,9,20,null,null,15,7]. Each node is a TreeNode with .val, .left and .right; the class is already defined for you.

Example 1

root [2,1,3,null,null,0,1]
returns true

0 AND 1 is False; 1 OR False is True.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Trees problems