修复bug

This commit is contained in:
游由 2021-11-16 16:27:57 +08:00
parent 0d822fc959
commit c4dba758da
1 changed files with 2 additions and 2 deletions

View File

@ -42,10 +42,10 @@ impl Solution {
/// * 👍 1603
/// * 👎 0
pub fn is_symmetric(root: Option<Rc<RefCell<TreeNode>>>) -> bool {
fn symmetric(t1: &Option<Rc<RefCell<TreeNode>>>, t2: &Option<Rc<RefCell<TreeNode>>>) -> bool {
fn check(t1: &Option<Rc<RefCell<TreeNode>>>, t2: &Option<Rc<RefCell<TreeNode>>>) -> bool {
match (t1, t2) {
(None, None) => true,
(Some(n1), Some(n2)) => n1.borrow().val == n2.borrow().val && symmetric(&n1.borrow().left, &n2.borrow().right) && symmetric(&n1.borrow().right, &n2.borrow().left),
(Some(n1), Some(n2)) => n1.borrow().val == n2.borrow().val && check(&n1.borrow().left, &n2.borrow().right) && check(&n1.borrow().right, &n2.borrow().left),
_ => false
}
}