Created
September 10, 2019 08:36
-
-
Save atul-chaudhary/97b002d2ebda819be00dad209c06e4c3 to your computer and use it in GitHub Desktop.
leetcode 101 symmetric tree recursive approach
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
# Definition for a binary tree node. | |
# class TreeNode: | |
# def __init__(self, x): | |
# self.val = x | |
# self.left = None | |
# self.right = None | |
class Solution: | |
def isSymmetric(self, root: TreeNode) -> bool: | |
if(root==None): | |
return True | |
else: | |
return self.check(root.left,root.right) | |
def check(self,left,right): | |
if(left==None and right==None): | |
return True | |
elif(left!=None and right!=None): | |
return (left.val==right.val) and self.check(left.left,right.right) and self.check(left.right,right.left) | |
else: | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment