Skip to content

Commit b3039cb

Browse files
authored
Create main.cpp
1 parent d1457df commit b3039cb

File tree

1 file changed

+22
-0
lines changed
  • 17 - Binary Tree Data Structure Problems/09 - Identical Trees

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)