Complete the code to check if two nodes are both None.
if p.is_none() && [1] { return true; }
Both nodes must be None to be symmetric at this point.
Complete the code to check if one node is None and the other is not.
if p.is_none() || [1] { return false; }
If one node is None and the other is Some, trees are not symmetric.
Fix the error in comparing the values of two nodes.
if p.as_ref().unwrap().borrow().val != [1].as_ref().unwrap().borrow().val { return false; }
We compare the value of node p with node q to check symmetry.
Fill both blanks to recursively check left and right children for symmetry.
return Self::is_symmetric_helper(p.as_ref().unwrap().borrow().[1].clone(), q.as_ref().unwrap().borrow().[2].clone()) && Self::is_symmetric_helper(p.as_ref().unwrap().borrow().right.clone(), q.as_ref().unwrap().borrow().left.clone());
We compare p's left with q's right and p's right with q's left recursively.
Fill all three blanks to complete the public method that starts the symmetry check.
pub fn is_symmetric(root: Option<Rc<RefCell<TreeNode>>>) -> bool {
if root.is_none() {
[1] true;
}
let root_ref = root.as_ref().unwrap();
Self::is_symmetric_helper(root_ref.borrow().[2].clone(), root_ref.borrow().[3].clone())
}If root is None, tree is symmetric by definition. Then we compare left and right children.
