@Scrazy
2017-04-12T09:32:16.000000Z
字数 356
阅读 935
python
算法
解法一:
# -*- coding:utf-8 -*-
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def isSymmetrical(self, pRoot):
def is_same(p1, p2):
if not (p1 or p2):
return True
elif p1 and p2 and p1.val == p2.val:
return is_same(p1.left, p2.right) and is_same(p1.right, p2.left)
return False
if not pRoot:
return True
return is_same(pRoot.left, pRoot.right)