Inorder Traversal C++ solution


#1

/**

  • Definition for binary tree
  • struct TreeNode {
  • int val;
    
  • TreeNode *left;
    
  • TreeNode *right;
    
  • TreeNode(int x) : val(x), left(NULL), right(NULL) {}
    
  • };
    /
    void inorder(TreeNode
    A,TreeNode*B,int &f)
    {
    if(A==nullptr and B==nullptr){if(f!=0)f=1;return;}
    if(A!= nullptr and B!=nullptr){
    inorder(A->left,B->left,f);
    if(A->val != B->val){f=0;return;}
    inorder(A->right,B->right,f);
    }
    else f=0;

}
int Solution::isSameTree(TreeNode* A, TreeNode* B) {
int res=1;
inorder(A,B,res);
return res;
}