Created
September 17, 2020 12:13
-
-
Save iamprayush/2e0fcbb7924f5124c5ec1901b8a7938d to your computer and use it in GitHub Desktop.
Symmetric Tree
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
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