[leetcode]python3 算法攻略-对称二叉树

给定一个二叉树,检查它是否是镜像对称的。

方案一:

class Solution(object):
    def isSymmetric(self, root):
        """
        :type root: TreeNode
        :rtype: bool
        """
        def issametree(l, r):
            if not l and not r:
                return True
            if l and r and l.val == r.val:
                return issametree(l.left, r.right) and issametree(r.left, l.right)
            else:
                return False
        if not root:
            return True
        return issametree(root.left, root.right)

猜你喜欢

转载自blog.csdn.net/zhenghaitian/article/details/81049819