101 Symmetric tree

class Solution:
def isSymmetric(self, root: Optional[TreeNode]) -> bool:
if root:
return self.helper(root.left,root.right)
return False
def helper(self,n1,n2):
if n1==None or n2==None :
return n1==n2
if n1.val != n2.val:
return False
return (self.helper(n1.left,n2.right) and self.helper(n1.right,n2.left))



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.