100. Same Tree
来源:互联网 发布:seo日志分析 编辑:程序博客网 时间:2024/06/10 22:08
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.
利用递归判断
class Solution
{
public:
bool isSameTree(TreeNode* p, TreeNode* q)
{
if(p==NULL&&q==NULL)
return true;
if(p==NULL&&q!=NULL)
return false;
if(p!=NULL&&q==NULL)
return false;
if(p!=NULL&&q!=NULL&&p->val!=q->val)
return false;
if(p!=NULL&&q!=NULL&&p->val==q->val)
return (isSameTree(p->right,q->right))&&(isSameTree(p->left,q->left));
}
};
阅读全文
0 0
- [LeetCode]100.Same Tree
- LeetCode 100. Same Tree
- 100.Same Tree
- 【LeetCode】100.Same Tree
- [Leetcode] 100. Same Tree
- [Leetcode] 100. Same Tree
- LeetCode --- 100. Same Tree
- LeetCode 100. Same Tree
- [leetcode] 100.Same Tree
- 100.Same Tree
- 100. Same Tree
- 100.Same Tree
- 100. Same Tree
- 100. Same Tree
- 100. Same Tree
- leetCode 100. Same Tree
- 100. Same Tree
- [LeetCode]100. Same Tree
- [LeetCode]152. Maximum Product Subarray
- Unity_标记语言_Xml文件
- Git的使用--将本地项目上传到Github
- HDU6201树形DP
- 剑指offer 30 最小的k个数
- 100. Same Tree
- 欢迎使用CSDN-markdown编辑器
- 请求转发与重定向的区别;
- 对应HTML dom,学习jQuery常见操作
- Codeforces 852D Exploration plan [spfa+二分+二分图匹配]
- Mysql服务启动脚本制作(win)
- 2017微软秋季校园招聘在线编程笔试-#1400 : Composition
- 1.如何在ArcGIS中生成缩略图?缩略图的作用是什么?
- web.xml中的web-app中出现Attribute "xsi:schemaLocation" must be declared for element type "web-app".