C++ Simple Pre-Order Traversal (5 line code)


#1

‘’’
int Solution::isSameTree(TreeNode* p, TreeNode* q)
{
if(!p && !q)
return true;

if(!p || !q)
    return false;
    
if(p->val != q->val)
    return false;
    
if(!isSameTree(p->left,q->left))
    return false;
else
    return isSameTree(p->right,q->right);

}
‘’’