Created
February 21, 2023 13:23
-
-
Save inside-code-yt/560f78a89a7e5f22fe44f46b04eae64c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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