您的位置:首页 > 其它

Leetcode 之Same Tree(48)

2016-06-01 14:12 169 查看
bool isSameTree(TreeNode *p, TreeNode *q)
{

stack<TreeNode *> s;
s.push(p);
s.push(q);
while (!s.empty())
{
q = s.top(); s.pop();
p = s.top(); s.pop();
//两个都为空
if (!p && !q)return true;
//一个为空
if (!p || !q)return false;
if (p->val != q->val)return false;

s.push(p->left);
s.push(q->left);

s.push(p->right);
s.push(q->right);
}
return true;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: