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.

做过symmetric tree再做这题就简单了,同时深搜两颗树,同时对比他们的左孩子和右孩子就可以了。

bool isSameTree(TreeNode *p, TreeNode *q) {
if (!p && !q) return true;
if (!(p && q)) return false;
if (p->val == q->val) {
return isSameTree(p->left, q->left) && isSameTree(p->right, q->right);
}
return false;
}

最新文章

  1. 天津政府应急系统之GIS一张图(arcgis api for flex)讲解(十一)路径导航模块
  2. WebForm 内置对象
  3. @SuppressWarnings忽略警告
  4. SQL如何将A,B,C替换为'A','B','C'
  5. ERROR com.opensymphony.xwork2.interceptor.ParametersInterceptor.error:34 - Developer Notification
  6. Uva(10048),最短路Floyd
  7. 3)Java容器
  8. 根据查询结果创建新表create table .. as (select....)
  9. 201521123079《java程序设计》第8周学习总结
  10. Common-used commands in Docker
  11. c# webBrowser 转图片
  12. Visual Studio学习记录
  13. Linux命令(一)
  14. R语言中的字符串处理函数
  15. ACM学习<3>
  16. BZOJ.4289.PA2012 Tax(思路 Dijkstra)
  17. StringBuffer 详解 (String系列之3)
  18. [Linux|DBA]运维三十六计
  19. 触电(by quqi99)
  20. Express文件上传之Multer

热门文章

  1. 5.3(2)----机器人走方格2(CC150)
  2. 实现Redis的主从复制配置
  3. php多线程抓取信息测试例子
  4. Linux 查找指定名称的进程并显示进程详细信息
  5. Increasing Triplet Subsequence
  6. C++基础知识面试精选100题系列(21-30)[C++ basics]
  7. 错误日志中关于innodb的问题收集
  8. 8.nodejs权威指南--MongoDB
  9. ZOJ 3812 We Need Medicine(dp、背包、状态压缩、路径记录)
  10. ajax+json+Struts2实现list传递实例讲解