diff --git "a/\346\225\260\346\215\256\347\273\223\346\236\204\347\263\273\345\210\227/\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\346\223\215\344\275\234\351\233\206\351\224\246.md" "b/\346\225\260\346\215\256\347\273\223\346\236\204\347\263\273\345\210\227/\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\346\223\215\344\275\234\351\233\206\351\224\246.md" index f792c187b65cb73d6d4c32d96562723e414eee6d..99b95ae03167f9068cee0d4a39c6dcbdd9acadbc 100644 --- "a/\346\225\260\346\215\256\347\273\223\346\236\204\347\263\273\345\210\227/\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\346\223\215\344\275\234\351\233\206\351\224\246.md" +++ "b/\346\225\260\346\215\256\347\273\223\346\236\204\347\263\273\345\210\227/\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\346\223\215\344\275\234\351\233\206\351\224\246.md" @@ -374,3 +374,29 @@ def isValidBST(self, root): ``` + +[lixiandea](https://github.com/lixiandea)提供第100题Python3代码: +```python3 +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def isSameTree(self, p: TreeNode, q: TreeNode) -> bool: + ''' + 当前节点值相等且树的子树相等,则树相等。 + 递归退出条件:两个节点存在一个节点为空 + ''' + if p == None: + if q == None: + return True + else: + return False + if q == None: + return False + # 当前节点相同且左子树和右子树分别相同 + return p.val==q.val and self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right) +``` +