比较两棵树是否相同
实现
def isSameTree(p, q):
if p == None and q == None:
return True
elif p != None and q != None:
return p.val == q.val and isSameTree(p.left, q.left) and isSameTree(p.right, q.right)
else:
return False
参考文献:
- https://leetcode.com/problems/same-tree/submissions/;
- 这是印象笔记中的笔记,如果是在CSDN手机APP上查看此博客,请在印象笔记手机APP中搜索该参考文献:https://app.yinxiang.com/shard/s44/nl/9329661/67840819-0c82-47a8-a4ba-ba87fbc26584;
- 19 求两棵树是否相同。