Skip to content

Commit 1f091a0

Browse files
authored
Merge pull request #46 from PriyanshK09/main
Create potd_24_10_2024.cpp
2 parents 9f1bec1 + 3bd6442 commit 1f091a0

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

october_2024/potd_24_10_2024.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* struct TreeNode {
4+
* int val;
5+
* TreeNode *left;
6+
* TreeNode *right;
7+
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
8+
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
9+
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left),
10+
* right(right) {}
11+
* };
12+
*/
13+
class Solution {
14+
public:
15+
bool flipEquiv(TreeNode* root1, TreeNode* root2) {
16+
if (root1 == NULL || root2 == NULL)
17+
return root1 == root2;
18+
if (root1->val != root2->val)
19+
return false;
20+
return (flipEquiv(root1->left, root2->left) &&
21+
flipEquiv(root1->right, root2->right)) ||
22+
flipEquiv(root1->left, root2->right) &&
23+
flipEquiv(root1->right, root2->left);
24+
}
25+
};

0 commit comments

Comments
 (0)