diff --git a/problems/100.same-tree.md b/problems/100.same-tree.md index febef643b..c19588d89 100644 --- a/problems/100.same-tree.md +++ b/problems/100.same-tree.md @@ -61,7 +61,7 @@ https://leetcode-cn.com/problems/same-tree/ ### 代码 -- 语言支持:CPP, JS, Go, PHP, CPP +- 语言支持:CPP, JS, Go, PHP, Python CPP Code: @@ -123,15 +123,18 @@ class Solution } ``` -CPP Code: - -```cpp -class Solution { -public: - bool isSameTree(TreeNode* p, TreeNode* q) { - return (!p && !q) || (p && q && p->val == q->val && isSameTree(p->left, q->left) && isSameTree(p->right, q->right)); - } -}; +Python Code: + +```Python +class Solution: + def isSameTree(self, p: TreeNode, q: TreeNode) -> bool: + if not p and not q: + return True + if not p or not q: + return False + if p.val != q.val: + return False + return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right) ``` **复杂度分析**