Skip to content

Commit

Permalink
Merge pull request #46 from PriyanshK09/main
Browse files Browse the repository at this point in the history
Create potd_24_10_2024.cpp
  • Loading branch information
Gyanthakur authored Oct 25, 2024
2 parents 9f1bec1 + 3bd6442 commit 1f091a0
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions october_2024/potd_24_10_2024.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left),
* right(right) {}
* };
*/
class Solution {
public:
bool flipEquiv(TreeNode* root1, TreeNode* root2) {
if (root1 == NULL || root2 == NULL)
return root1 == root2;
if (root1->val != root2->val)
return false;
return (flipEquiv(root1->left, root2->left) &&
flipEquiv(root1->right, root2->right)) ||
flipEquiv(root1->left, root2->right) &&
flipEquiv(root1->right, root2->left);
}
};

0 comments on commit 1f091a0

Please sign in to comment.