Skip to content

Commit

Permalink
Update 二叉树中递归带着回溯.md
Browse files Browse the repository at this point in the history
  • Loading branch information
fwqaaq authored Nov 18, 2022
1 parent 1f8ea7b commit 944ce27
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions problems/二叉树中递归带着回溯.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Rc<RefCell<TreeNode>>>,
q: Option<Rc<RefCell<TreeNode>>>,
) -> 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
}
}
}
}
}
```


<p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
Expand Down

0 comments on commit 944ce27

Please sign in to comment.