Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Definition for binary tree
- * struct TreeNode {
- * int val;
- * TreeNode *left;
- * TreeNode *right;
- * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
- * };
- */
- int ans;
- bool fun(TreeNode* t1,TreeNode* t2){
- if(!t1)
- return t2 == nullptr;
- if(!t2)
- return false;
- if(t1->val == t2->val){
- bool flg = fun(t1->left,t2->left) and fun(t1->right,t2->right);
- if(!flg){
- ans++;
- return fun(t1->left,t2->right) and fun(t1->right,t2->left);
- }else return true;
- }else
- return false;
- }
- int Solution::solve(TreeNode* A, TreeNode* B) {
- ans = 0;
- if(fun(A,B))
- return ans;
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement