Same Tree
2013-11-14 08:05
225 查看
Given two binary trees, write a function to check if they are equal or not.
Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
Code:
Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
Code:
class Solution { public: bool isSameTree(TreeNode *p, TreeNode *q) { if(p&&q){ if(p->val!=q->val) return false; if(!isSameTree(p->left,q->left)) return false; if(!isSameTree(p->right,q->right)) return false; return true; } else if(!p&&!q) return true; else return false; } };
相关文章推荐
- LRU Cache
- POJ:1922 Ride to School
- 如何更好地学习dubbo源代码
- Berkeley 四种产品如何选择?
- java数组基础
- 上淘宝找人设计logo被坑了
- Http响应头字段详解,MyEclipse配置tomcat,servlet运行方式
- java学习基础要点笔记
- 【虚拟化实战】Cluster设计之一资源池
- 远程分支和本地分支的相互创建和跟踪
- 【虚拟化实战】Cluster设计之一资源池
- 【虚拟化实战】Cluster设计之一资源池 推荐
- 如何手动清除Windows上Domino的安装信息
- Domino上如何配置ID vault账户环境
- Android4.2原生Camera、Gallery导入Eclipse 补充说明
- php checkbox复选框值的获取与checkbox默认值输出方法
- php构造函数的小例子
- jsp base标签与meta标签学习小结
- 使用php验证复选框有效性的示例
- php验证复选框有效性的示例