Skip to content

Commit a86c141

Browse files
committed
100.IsSameTree
1 parent 1bc470f commit a86c141

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Tree/Tree.TreeLib/SameTree.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* ==============================================================================
2+
* 功能描述:SameTree
3+
* 创 建 者:gz
4+
* 创建日期:2017/4/20 8:35:40
5+
* ==============================================================================*/
6+
7+
//Given two binary trees, write a function to check if they are equal or not.
8+
//Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
9+
namespace Tree.TreeLib
10+
{
11+
/// <summary>
12+
/// SameTree
13+
/// </summary>
14+
public class SameTree
15+
{
16+
17+
public bool IsSameTree(TreeNode p, TreeNode q)
18+
{
19+
if (p == null && q == null) return true;
20+
if (p == null || q == null) return false;
21+
return p.val == q.val &&
22+
IsSameTree(p.left, q.left) &&
23+
IsSameTree(p.right, q.right);
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)