From 5e21dbd9a07409a1d991b1fabb8868dff20816b8 Mon Sep 17 00:00:00 2001 From: Dale Seo <5466341+DaleSeo@users.noreply.github.com> Date: Sat, 23 May 2026 15:53:50 -0400 Subject: [PATCH] same-tree --- same-tree/DaleSeo.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 same-tree/DaleSeo.rs 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, + } + } +}