diff --git a/same-tree/DaleSeo.rs b/same-tree/DaleSeo.rs new file mode 100644 index 000000000..804a94bf0 --- /dev/null +++ b/same-tree/DaleSeo.rs @@ -0,0 +1,23 @@ +// TC: O(n) +// SC: O(n) +use std::cell::RefCell; +use std::rc::Rc; + +impl Solution { + pub fn is_same_tree( + p: Option>>, + q: Option>>, + ) -> bool { + match (p, q) { + (None, None) => true, + (Some(a), Some(b)) => { + let a = a.borrow(); + let b = b.borrow(); + a.val == b.val + && Self::is_same_tree(a.left.clone(), b.left.clone()) + && Self::is_same_tree(a.right.clone(), b.right.clone()) + } + _ => false, + } + } +}