Skip to content

Commit 78c6e36

Browse files
authored
Merge pull request #1988 from AkifhanIlgaz/0100
Create: 0100-same-tree.rs
2 parents cc4c59e + 627934b commit 78c6e36

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

rust/0100-same-tree.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use std::cell::RefCell;
2+
use std::rc::Rc;
3+
impl Solution {
4+
pub fn is_same_tree(
5+
p: Option<Rc<RefCell<TreeNode>>>,
6+
q: Option<Rc<RefCell<TreeNode>>>,
7+
) -> bool {
8+
match (p, q) {
9+
(None, None) => true,
10+
(Some(p), Some(q)) => {
11+
let p = p.borrow();
12+
let q = q.borrow();
13+
p.val == q.val
14+
&& Self::is_same_tree(p.left.clone(), q.left.clone())
15+
&& Self::is_same_tree(p.right.clone(), q.right.clone())
16+
}
17+
_ => false,
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)