Skip to content

Instantly share code, notes, and snippets.

@atul-chaudhary
Created September 10, 2019 08:36
Show Gist options
  • Save atul-chaudhary/97b002d2ebda819be00dad209c06e4c3 to your computer and use it in GitHub Desktop.
Save atul-chaudhary/97b002d2ebda819be00dad209c06e4c3 to your computer and use it in GitHub Desktop.
leetcode 101 symmetric tree recursive approach
# 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