From 944ce27a28b6582e71f3626c39708e84ec4a0c34 Mon Sep 17 00:00:00 2001 From: fw_qaq <82551626+Jack-Zhang-1314@users.noreply.github.com> Date: Sat, 19 Nov 2022 00:07:04 +0800 Subject: [PATCH] =?UTF-8?q?Update=20=E4=BA=8C=E5=8F=89=E6=A0=91=E4=B8=AD?= =?UTF-8?q?=E9=80=92=E5=BD=92=E5=B8=A6=E7=9D=80=E5=9B=9E=E6=BA=AF.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/二叉树中递归带着回溯.md | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/problems/二叉树中递归带着回溯.md b/problems/二叉树中递归带着回溯.md index e35a5214..dc576c60 100644 --- a/problems/二叉树中递归带着回溯.md +++ b/problems/二叉树中递归带着回溯.md @@ -617,6 +617,38 @@ func _binaryTreePaths3(_ root: TreeNode, res: inout [String], paths: inout [Int] } ``` +### Rust + +> 100.相同的树 + +```rsut +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, + (None, Some(_)) => false, + (Some(_), None) => false, + (Some(n1), Some(n2)) => { + if n1.borrow().val == n2.borrow().val { + let right = + Self::is_same_tree(n1.borrow().left.clone(), n2.borrow().left.clone()); + let left = + Self::is_same_tree(n1.borrow().right.clone(), n2.borrow().right.clone()); + right && left + } else { + false + } + } + } + } +} +``` +