leetcode101.对称二叉树python

二叉树一般采用递归方法,于是新建函数

def f(p, q):
            if p == None:
                return q == None
            if q == None:
                return p == None
            if p.val == q.val:
                return f(p.left, q.right) and f(p.right, q.left)
            if p.val != q.val:
                return False
        if root == None:
            return True
        return f(root.left, root.right)

你可能感兴趣的:(leetcode101.对称二叉树python)