【剑指offer】对称的二叉树(Python)

解题思路很像“树的子结构”那题。

# -*- coding:utf-8 -*-
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None
class Solution:
    def Define(self,A,B):
        if not A and not B:
            return True
        if not A or not B:
            return False
        if A.val != B.val:
            return False
        return self.Define(A.left,B.right) and self.Define(A.right,B.left)
    def isSymmetrical(self, pRoot):
        # write code here
        if not pRoot:
            return True
        return self.Define(pRoot.left, pRoot.right)