From 3bd64424ec89efdc3445bc22f8481b9551e1e22a Mon Sep 17 00:00:00 2001 From: Priyansh Khare <75330418+PriyanshK09@users.noreply.github.com> Date: Thu, 24 Oct 2024 15:13:12 +0530 Subject: [PATCH] Create potd_24_10_2024.cpp Problem of the Day (October 24) --- october_2024/potd_24_10_2024.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 october_2024/potd_24_10_2024.cpp diff --git a/october_2024/potd_24_10_2024.cpp b/october_2024/potd_24_10_2024.cpp new file mode 100644 index 0000000..ad524d3 --- /dev/null +++ b/october_2024/potd_24_10_2024.cpp @@ -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); + } +};