Skip to content

Commit

Permalink
Create: 0100-same-tree.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
AkifhanIlgaz committed Jan 10, 2023
1 parent ee7a3bc commit 627934b
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 627934b

Please sign in to comment.