Tap here to switch tabs
Problem
Submissions

Problem: Evaluate Boolean Binary Tree

Try to solve the Evaluate Boolean Binary Tree problem.

Statement

You are given the root of a full binary tree with the following properties:

  • Leaf nodes have a value of 00 or 11, representing False and True respectively.

  • Non leaf nodes have a value of 22 or 33, representing the boolean OR and boolean AND operations respectively.

The evaluation of a node is defined as:

  • If the node is a leaf, its evaluation is the boolean value represented by its value (00 for False and 11 for True).

  • Otherwise, evaluate the left and right children and apply the boolean operation corresponding to the current node (22 for OR, 33 for AND) to their evaluated results.

Return the boolean result of evaluating the root node.

Constraints:

  • The number of nodes in the tree is in the range [1,1000][1, 1000].

  • 0≤0 \leq Node.val ≤3\leq 3

  • Every node has either 00 or 22 children.

  • Leaf nodes have a value of 00 or 11.

  • Non leaf nodes have a value of 22 or 33.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Evaluate Boolean Binary Tree

Try to solve the Evaluate Boolean Binary Tree problem.

Statement

You are given the root of a full binary tree with the following properties:

  • Leaf nodes have a value of 00 or 11, representing False and True respectively.

  • Non leaf nodes have a value of 22 or 33, representing the boolean OR and boolean AND operations respectively.

The evaluation of a node is defined as:

  • If the node is a leaf, its evaluation is the boolean value represented by its value (00 for False and 11 for True).

  • Otherwise, evaluate the left and right children and apply the boolean operation corresponding to the current node (22 for OR, 33 for AND) to their evaluated results.

Return the boolean result of evaluating the root node.

Constraints:

  • The number of nodes in the tree is in the range [1,1000][1, 1000].

  • 0≤0 \leq Node.val ≤3\leq 3

  • Every node has either 00 or 22 children.

  • Leaf nodes have a value of 00 or 11.

  • Non leaf nodes have a value of 22 or 33.