-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from PriyanshK09/main
Create potd_24_10_2024.cpp
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; |