Symmetric Tree (Leetcode 101)
Problem Link: https://leetcode.com/problems/symmetric-tree/
class Solution:
def isSymmetric(self, root: Optional[TreeNode]) -> bool:
lroot=root.left
rroot=root.right
def fun(lroot,rroot):
if(lroot is None and rroot is None):
return True
if(lroot is None or rroot is None):
return False
f=fun(lroot.left,rroot.right)
s=fun(lroot.right,rroot.left)
if(lroot.val==rroot.val and f and s):
return True
return False
return fun(lroot,rroot)
Last updated