22 else if ((p && !q) || (!p && q))
24 queue<pair<TreeNode*, TreeNode*>> nodes;
26 while (!nodes.empty())
28 auto [pt, qt] = nodes.front();
31 if ((pt && !qt) || (!pt && qt) || pt->val != qt->val)
33 if (pt->left || qt->left)
34 nodes.push({pt->left, qt->left});
35 if (pt->right || qt->right)
36 nodes.push({pt->right, qt->right});