Complete the code to check if two nodes are both None.
def is_symmetric_helper(node1, node2): if node1 is [1] and node2 is None: return True
We check if both nodes are None to confirm symmetry at this branch.
Complete the code to check if the values of two nodes are equal.
def is_symmetric_helper(node1, node2): if node1 is None or node2 is None: return False if node1.val [1] node2.val: return False
If the values are not equal, the trees are not symmetric.
Fix the error in the recursive call to check symmetry of subtrees.
def is_symmetric_helper(node1, node2): if node1 is None and node2 is None: return True if node1 is None or node2 is None: return False if node1.val != node2.val: return False return is_symmetric_helper(node1.left, [1]) and is_symmetric_helper(node1.right, node2.left)
We compare node1's left subtree with node2's right subtree for symmetry.
Fill both blanks to complete the main function that starts the symmetry check.
def is_symmetric(root): if root is None: return True return is_symmetric_helper(root.[1], root.[2])
The symmetry check starts by comparing the left and right children of the root.
Fill all three blanks to complete the recursive symmetry check combining conditions.
def is_symmetric_helper(node1, node2): if node1 is None and node2 is None: return True if node1 is None or node2 is None: return False if node1.val != node2.val: return False return is_symmetric_helper(node1.[1], node2.[2]) and is_symmetric_helper(node1.[3], node2.[4])
The function compares node1's left with node2's right and node1's right with node2's left recursively.
