Skip to content

Instantly share code, notes, and snippets.

@inside-code-yt
Created February 21, 2023 13:23
Show Gist options
  • Save inside-code-yt/560f78a89a7e5f22fe44f46b04eae64c to your computer and use it in GitHub Desktop.
Save inside-code-yt/560f78a89a7e5f22fe44f46b04eae64c to your computer and use it in GitHub Desktop.
def are_symmetric(root1, root2)
if root1 is None and root2 is None:
return True
elif ((root1 is None) != (root2 is None)) or root1.val != root2.val
return False
else:
return are_symmetric(root1.left, root2.right) and are_symmetric(root1.right, root2.left)
def is_symmetric(root):
if root is None:
return True
return are_symmetric(root.left, root.right)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment