剑指 Offer 28. 对称的二叉树

solution

recursive

class Solution:
    def isSymmetric(self, root: TreeNode) -> bool:
        def helper(q, p):
            if not q and not p:
                return True
            if not q and p:
                return False
            if q and not p:
                return False
            if p.val != q.val:
                return False
            return helper(q.left, p.right) and helper(q.right, p.left)
        if not root:
            return True
        return helper(root.left, root.right)
原文地址:https://www.cnblogs.com/fengcnblogs/p/13514813.html