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 a957c0a + cec6743 commit 257dfc5Copy full SHA for 257dfc5
Trees/tree_foldable.cpp
@@ -0,0 +1,28 @@
1
+// check if a Tree is foldable or not
2
+
3
+// approach:
4
+// If one of the two trees is empty, return false; if both are empty, return true
5
+// If one of the subtree is found out to be mirror of the other one, return true
6
7
+bool find(node *node1, node *node2)
8
+{
9
+ if (node1 == NULL && node2 == NULL)
10
+ {
11
+ return true;
12
+ }
13
+ if (node1 == NULL || node2 == NULL)
14
15
+ return false;
16
17
+ return find(node1->left, node2->right) && find(node1->right, node2->left);
18
+}
19
20
+bool foldableCheck(node *root)
21
22
+ if (root == NULL)
23
24
25
26
27
+ return find(root->left, root->right);
28
0 commit comments