Skip to content

Instantly share code, notes, and snippets.

@iamprayush
Created September 17, 2020 12:13
Show Gist options
  • Save iamprayush/2e0fcbb7924f5124c5ec1901b8a7938d to your computer and use it in GitHub Desktop.
Save iamprayush/2e0fcbb7924f5124c5ec1901b8a7938d to your computer and use it in GitHub Desktop.
Symmetric Tree
class Solution:
def isSymmetric(self, root: TreeNode) -> bool:
return self.isMirror(root, root)
def isMirror(self, left_node: TreeNode, right_node: TreeNode) -> bool:
if not left_node and not right_node:
return True
if (not left_node) or (not right_node):
return False
if left_node.val != right_node.val:
return False
return self.isMirror(
left_node.left, right_node.right) and self.isMirror(
left_node.right, right_node.left)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment