File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments