```
def isSameTree(self, p, q):
"""
:type p: TreeNode
:type q: TreeNode
:rtype: bool
"""
if p == q == None: return True
elif not (p and q and p.val == q.val): return False
else: return self.isSameTree(p.left,q.left) and self.isSameTree(p.right,q.right)
```