Skip to content

Commit a425de8

Browse files
committedFeb 6, 2023
solve leetcode 1331
1 parent 7153028 commit a425de8

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed
 

Diff for: ‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ leetcode_solutions
568568
|2299|[Strong Password Checker II](https://leetcode.cn/problems/strong-password-checker-ii/)|[Rust](src/easy/leetcode_very_easy.rs)|
569569
|2319|[Check If Matrix...](https://leetcode.cn/problems/check-if-matrix-is-x-matrix/)|[Rust](src/easy/leetcode_very_easy.rs)|
570570
|2325|[Decode The Message](https://leetcode.cn/problems/decode-the-message/)|[Rust](src/easy/leetcode_very_easy.rs)|
571+
|2331|[Evaluate Boolean Binary Tree](https://leetcode.cn/problems/evaluate-boolean-binary-tree/)|[Rust](src/binary_tree/evaluate_boolean_binary_tree.rs)|
571572

572573
---
573574

Diff for: ‎src/binary_tree/evaluate_boolean_binary_tree.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use super::prelude::*;
2+
3+
/// https://leetcode.cn/problems/evaluate-boolean-binary-tree/
4+
fn evaluate_tree(root: Option<Rc<RefCell<TreeNode>>>) -> bool {
5+
let root = root.unwrap();
6+
let root = root.borrow();
7+
if root.left.is_none() && root.right.is_none() {
8+
return root.val == 1;
9+
}
10+
let left = evaluate_tree(root.left.clone());
11+
let right = evaluate_tree(root.right.clone());
12+
if root.val == 2 {
13+
left || right
14+
} else {
15+
left && right
16+
}
17+
}

Diff for: ‎src/binary_tree/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
mod evaluate_boolean_binary_tree;
12
#[cfg(feature = "rustc_private")]
23
mod graphviz_view_leetcode_binary_tree;
34
mod invert_binary_tree;

0 commit comments

Comments
 (0)
Please sign in to comment.