Problem Statement

Given two binary trees, write a function to check if they are equal or not.

Two binary trees are considered equal if they are structurally identical and the nodes have the same value.

Return 0 / 1 ( 0 for false, 1 for true ) for this problem

Example :

`Input :

1 1 / \ / \ 2 3 2 3

Output : 1 or True`

Problem Link

Identical Binary Trees - InterviewBit

Code

/**
 * Definition for binary tree
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
int Solution::isSameTree(TreeNode* A, TreeNode* B) {
    
    if(A == NULL ^ B == NULL) {
        return false;
    }
    
    if(A == NULL && B == NULL) {
        return true;
    }
    
    
    return A->val==B->val && isSameTree(A->left,B->left) && isSameTree(A->right,B->right);
   
}