Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1988 from AkifhanIlgaz/0100
Browse files Browse the repository at this point in the history
Create: 0100-same-tree.rs
  • Loading branch information
tahsintunan authored Jan 10, 2023
2 parents cc4c59e + 627934b commit 78c6e36
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions rust/0100-same-tree.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use std::cell::RefCell;
use std::rc::Rc;
impl Solution {
pub fn is_same_tree(
p: Option<Rc<RefCell<TreeNode>>>,
q: Option<Rc<RefCell<TreeNode>>>,
) -> bool {
match (p, q) {
(None, None) => true,
(Some(p), Some(q)) => {
let p = p.borrow();
let q = q.borrow();
p.val == q.val
&& Self::is_same_tree(p.left.clone(), q.left.clone())
&& Self::is_same_tree(p.right.clone(), q.right.clone())
}
_ => false,
}
}
}

0 comments on commit 78c6e36

Please sign in to comment.