# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
#
#
# @param p TreeNode类
# @param q TreeNode类
# @return bool布尔型
#
class Solution:
def isSameTree(self , p , q ):
# write code here
# 两者都为None则返回True
if not p and not q:
return True
# 其中一个为None则返回False
if not ***ot q:
return False
# 都不为None则比较值
if p.val != q.val:
return False
# 对左右子树分别进行递归比较
return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)