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.
1 parent d1457df commit b3039cbCopy full SHA for b3039cb
17 - Binary Tree Data Structure Problems/09 - Identical Trees/main.cpp
@@ -0,0 +1,22 @@
1
+class Solution
2
+{
3
+ public:
4
+ //Function to check if two trees are identical.
5
+ bool isIdentical(Node *r1, Node *r2)
6
+ {
7
+
8
+ if(r1 == NULL && r2 == NULL) return true;
9
+ if(r1 == NULL && r2 != NULL) return false;
10
+ if(r1 != NULL && r2 == NULL) return false;
11
12
+ bool left = isIdentical(r1 -> left, r2 -> left);
13
+ bool right = isIdentical(r1 -> right, r2 -> right);
14
15
+ bool value = r1 -> data == r2 -> data;
16
17
+ if(left && right && value) return true;
18
19
20
+ return false;
21
+ }
22
+};
0 commit comments