美文网首页
02_对称二叉树

02_对称二叉树

作者: butters001 | 来源:发表于2019-11-12 10:48 被阅读0次
class Solution(object):
    def isSymmetric(self, root):
        """
        :type root: TreeNode
        :rtype: bool
        """
        def helper(p, q):
            if not p and not q:
                return True
            if not p or not q:
                return False
            if p.val == q.val:
                return helper(p.left, q.right) and helper(p.right, q.left)
            else:
                return False

        return helper(root, root)

相关文章

网友评论

      本文标题:02_对称二叉树

      本文链接:https://www.haomeiwen.com/subject/slufictx.html