Easy C++ solution | O(n) time complexity


#1
int Solution::isSameTree(TreeNode* A, TreeNode* B)
{
    if(!A && !B)
    {
        return true;
    }
    else if(!A && B)
    {
        return false;
    }
    else if(A && !B)
    {
        return false;
    }
    else if(A->val==B->val)
    {
        return isSameTree(A->left,B->left) && isSameTree(A->right,B->right);
    }
    else
    {
        return false;
    }
}