1. Same Tree My Submissions QuestionEditorial Solution

    Total Accepted: 126116 Total Submissions: 291884 Difficulty: Easy

    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.

Subscribe to see which companies asked this question

思路:太简单,主要p,q为空考虑到,并用一行代码实现

/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
bool isSameTree(TreeNode* p, TreeNode* q) {
if(p==NULL||q==NULL)return p==q;
if(p->val==q->val)
return isSameTree(p->left,q->left)&&isSameTree(p->right,q->right);
else return false;
}
};

最新文章

  1. LINQ to SQL Where条件
  2. 重复加载同一个jqgrid
  3. Unity3D上可以发布到IOS使用的SQLite数据库
  4. 关于ApplicationPoolIdentity
  5. C#中位、字节等知识
  6. django 学习-1
  7. bzoj2242
  8. ZendFramework使用中常见问题
  9. tomcat发布静态网页
  10. C 语言中的变量为什么不能以数字打头
  11. C++中 auto自己主动变量,命名空间,using作用以及作用域
  12. 在 Linux 环境下报错 java.lang.reflect.InvocationTargetException
  13. LVS的DR设置测试
  14. centos7环境搭建命令List
  15. 左耳听风-ARTS-第3周(2019/4/7-2019/4/13)
  16. Hashtable与Dictionary比较
  17. 配置cron定时任务
  18. 操作系统学习笔记(二) 页式映射及windbg验证方式
  19. unwrap bug
  20. Nowcoder 提高组练习赛-R7

热门文章

  1. 【二食堂】Alpha- 发布声明
  2. Noip模拟5 2021.6.7
  3. Java并发:Condition接口
  4. 【代码更新】单细胞分析实录(20): 将多个样本的CNV定位到染色体臂,并画热图
  5. uvm中类继承和phase
  6. 近期业务大量突增微服务性能优化总结-3.针对 x86 云环境改进异步日志等待策略
  7. kvm 安装 windows 虚拟机
  8. k8s入坑之路(14)scheduler调度 kubelet管理及健康检查 更新策略
  9. Python之模块导入(不看会后悔系列)
  10. Python多版本共存的方法