root. Every node has either no children or exactly two.
- A leaf is an input of the circuit: 0 stands for false and 1 for true.
- An inner node is a gate: 2 means OR and 3 means AND. A gate applies its operation to the values of its left and right subtrees.
Return the output of the circuit, which is the value of the root, as True or False.root=tree_node([3, 2, 1, 0, 1]) → True
The left node is an OR of 0 and 1, which is true. The root is an AND of that and the right leaf 1, so it is true as well.
root=tree_node([3, 1, 2, None, None, 0, 0]) → False
The right node is an OR of two zeros, which is false. The root is an AND with a false input, so the output is false.
root=tree_node([1]) → True
A circuit with a single input simply outputs that input.
root=tree_node([3, 2, 1, 0, 1])
True
Run checks the first 3 tests in your browser. Submit checks all 20 tests on the server, hidden ones included.