Skip to content

Commit

Permalink
Removed duplicate CPP solution for problem 100.same-tree and added Py…
Browse files Browse the repository at this point in the history
…thon solution
  • Loading branch information
idebbarh committed Jan 28, 2023
1 parent 02a9225 commit bbffe86
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions problems/100.same-tree.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ https://leetcode-cn.com/problems/same-tree/

### 代码

- 语言支持:CPP, JS, Go, PHP, CPP
- 语言支持:CPP, JS, Go, PHP, Python

CPP Code:

Expand Down Expand Up @@ -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)
```

**复杂度分析**
Expand Down

0 comments on commit bbffe86

Please sign in to comment.