1 # -*- coding:utf-8 -*- 2 # class TreeNode: 3 # def __init__(self, x): 4 # self.val = x 5 # self.left = None 6 # self.right = None 7 class Solution: 8 def isSameTree(self,left,right): 9 if left != None and right != None: 10 if left.val != right.val: 11 return False 12 else: 13 return self.isSameTree(left.left,right.right) and self.isSameTree(left.right,right.left) 14 if left == None and right == None: 15 return True 16 else: 17 return False 18 19 def isSymmetrical(self, pRoot): 20 if pRoot == None: 21 return True 22 return self.isSameTree(pRoot.left,pRoot.right) 23 # write code here