pub fn is_subtree(
        mut root: Option<Rc<RefCell<TreeNode>>>,
        sub_root: Option<Rc<RefCell<TreeNode>>>,
    ) -> bool {
        if root.is_none() && sub_root.is_none() {
            return true;
        } else if root.is_some() && sub_root.is_some() {
            if Solution::compare_tree(root.clone(), sub_root.clone()) {
                return true;
            }

            // If they are not equal
            // The left and right subtrees are used to make the determination.

            let left = root.as_mut().map(|r| r.borrow_mut().left.take()).flatten();

            if Solution::is_subtree(left, sub_root.clone()) {
                return true;
            }

            let right = root.as_mut().map(|r| r.borrow_mut().right.take()).flatten();

            if Solution::is_subtree(right, sub_root) {
                return true;
            }

            return false;
        } else {
            return false;
        }
    }
// Recursively traverses whether two trees are equal.
Recursively traverses whether two trees are equal.
Recursively traverses whether two trees are equal .
pub fn is_subtree(
        mut root: Option<Rc<RefCell<TreeNode>>>,
        sub_root: Option<Rc<RefCell<TreeNode>>>,
    ) -> bool {
        if root.is_none() && sub_root.is_none() {
            return true;
        } else if root.is_some() && sub_root.is_some() {
            if Solution::compare_tree(root.clone(), sub_root.clone()) {
                return true;
            }
            // If they are not equal
            // The left and right subtrees are used to make the determination.
            let left = root.as_mut().map(|r| r.borrow_mut().left.take()).flatten();
            if Solution::is_subtree(left, sub_root.clone()) {
                return true;
            }
            let right = root.as_mut().map(|r| r.borrow_mut().right.take()).flatten();
            if Solution::is_subtree(right, sub_root) {
                return true;
            }
            return false;
        } else {
            return false;
        }
    }
pub fn is_subtree ( mut root : Option < Rc < RefCell < TreeNode > > > , sub_root : Option < Rc < RefCell < TreeNode > > > , ) -> bool { if root . is_none ( ) && sub_root . is_none ( ) { return true ; } else if root . is_some ( ) && sub_root . is_some ( ) { if Solution :: compare_tree ( root . clone ( ) , sub_root . clone ( ) ) { return true ; } // If they are not equal // The left and right subtrees are used to make the determination. let left = root . as_mut ( ) . map ( | r | r . borrow_mut ( ) . left . take ( ) ) . flatten ( ) ; if Solution :: is_subtree ( left , sub_root . clone ( ) ) { return true ; } let right = root . as_mut ( ) . map ( | r | r . borrow_mut ( ) . right . take ( ) ) . flatten ( ) ; if Solution :: is_subtree ( right , sub_root ) { return true ; } return false ; } else { return false ; } }
Recursively traverses whether two trees are equal.
Recursively traverses whether two trees are equal .
root
Option<Rc<RefCell<TreeNode>>>
sub_root
Option<Rc<RefCell<TreeNode>>>
root
Option<Rc<RefCell<TreeNode>>>
sub_root
Option<Rc<RefCell<TreeNode>>>