> For the complete documentation index, see [llms.txt](https://nataliekung.gitbook.io/solutions/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nataliekung.gitbook.io/solutions/same_tree.md).

# Same Tree

bool isSameTree(TreeNode *p, TreeNode* q) {

stack\<TreeNode\*> s;

TreeNode *a,*&#x62;;

s.push(p);

s.push(q);

while(!s.empty()){

a=s.top();

s.pop();

b=s.top();

s.pop();

if(!a&&!b) //剪枝

continue;

if(!a||!b)

return false;

if(a->val!=b->val)

return false;

s.push(a->left);

s.push(b->left);

s.push(a->right);

s.push(b->right);

}

return true;

}
