#题目内容
给定一个二叉树,检查它是否是镜像对称的。
例如,二叉树【1,2,2,3,4,4,3】是对称的。
但是下面这个【1,2,2,null,3,null,3】则不是对称的。
#解题思路
这个可以转换成两个相同的树判别,只是判断左子树和右子树相同
class Solution:
def isSymmetric(self, root: TreeNode) -> bool:
if root == None:
return True
def Tree(q,p):
if not q and not p:
return True
elif q and p and q.val == p.val:
return Tree(q.left,p.right) and Tree(q.right,p.left)
else:
return False
return Tree(root.left,root.right)