2331. Evaluate Boolean Binary Tree Easy
1/**
2 * [2331] Evaluate Boolean Binary Tree
3 *
4 * You are given the root of a full binary tree with the following properties:
5 *
6 * Leaf nodes have either the value 0 or 1, where 0 represents False and 1 represents True.
7 * Non-leaf nodes have either the value 2 or 3, where 2 represents the boolean OR and 3 represents the boolean AND.
8 *
9 * The evaluation of a node is as follows:
10 *
11 * If the node is a leaf node, the evaluation is the value of the node, i.e. True or False.
12 * Otherwise, evaluate the node's two children and apply the boolean operation of its value with the children's evaluations.
13 *
14 * Return the boolean result of evaluating the root node.
15 * A full binary tree is a binary tree where each node has either 0 or 2 children.
16 * A leaf node is a node that has zero children.
17 *
18 * Example 1:
19 * <img alt="" src="https://assets.leetcode.com/uploads/2022/05/16/example1drawio1.png" style="width: 700px; height: 252px;" />
20 * Input: root = [2,1,3,null,null,0,1]
21 * Output: true
22 * Explanation: The above diagram illustrates the evaluation process.
23 * The AND node evaluates to False AND True = False.
24 * The OR node evaluates to True OR False = True.
25 * The root node evaluates to True, so we return true.
26 * Example 2:
27 *
28 * Input: root = [0]
29 * Output: false
30 * Explanation: The root node is a leaf node and it evaluates to false, so we return false.
31 *
32 *
33 * Constraints:
34 *
35 * The number of nodes in the tree is in the range [1, 1000].
36 * 0 <= Node.val <= 3
37 * Every node has either 0 or 2 children.
38 * Leaf nodes have a value of 0 or 1.
39 * Non-leaf nodes have a value of 2 or 3.
40 *
41 */
42pub struct Solution {}
43use crate::util::tree::{TreeNode, to_tree};
44
45// problem: https://leetcode.com/problems/evaluate-boolean-binary-tree/
46// discuss: https://leetcode.com/problems/evaluate-boolean-binary-tree/discuss/?currentPage=1&orderBy=most_votes&query=
47
48// submission codes start here
49
50// Definition for a binary tree node.
51// #[derive(Debug, PartialEq, Eq)]
52// pub struct TreeNode {
53// pub val: i32,
54// pub left: Option<Rc<RefCell<TreeNode>>>,
55// pub right: Option<Rc<RefCell<TreeNode>>>,
56// }
57//
58// impl TreeNode {
59// #[inline]
60// pub fn new(val: i32) -> Self {
61// TreeNode {
62// val,
63// left: None,
64// right: None
65// }
66// }
67// }
68use std::rc::Rc;
69use std::cell::RefCell;
70impl Solution {
71 pub fn evaluate_tree(root: Option<Rc<RefCell<TreeNode>>>) -> bool {
72 false
73 }
74}
75
76// submission codes end
77
78#[cfg(test)]
79mod tests {
80 use super::*;
81
82 #[test]
83 fn test_2331() {
84 }
85}
86
Back
© 2025 bowen.ge All Rights Reserved.