We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 6d74f4f + 1dc338e commit 8fd4c47Copy full SHA for 8fd4c47
solution/0100.Same Tree/README.md
@@ -0,0 +1,40 @@
1
+## 相同的树
2
+### 题目描述
3
+
4
+给定两个二叉树,编写一个函数来检验它们是否相同。
5
+如果两个树在结构上相同,并且节点具有相同的值,则认为它们是相同的。
6
7
+示例 1:
8
+```
9
+输入: 1 1
10
+ / \ / \
11
+ 2 3 2 3
12
13
+ [1,2,3], [1,2,3]
14
15
+输出: true
16
17
18
19
+示例 2:
20
21
22
+ / \
23
+ 2 2
24
25
+ [1,2], [1,null,2]
26
27
+输出: false
28
29
30
31
+示例 3:
32
33
34
35
+ 2 1 1 2
36
37
+ [1,2,1], [1,1,2]
38
39
40
solution/0100.Same Tree/Solution.go
@@ -0,0 +1,12 @@
+func isSameTree(p *TreeNode, q *TreeNode) bool {
+ if p == nil && q == nil {
+ return true
+ }
+ if p == nil || q == nil {
+ return false
+ if p.Val != q.Val {
+ return isSameTree(p.Left, q.Left) && isSameTree(p.Right, q.Right)
+}
0 commit comments