```
def isSameTree(self, p, q):
if p and q and p.val != q.val:
return False
if p == None and q == None:
return True
elif p == None or q == None:
return False
return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)
```

Your feedback is appreciated. I am wondering if there is a more elegant way of doing this.