LeetCode 100. Same Tree
2016-04-16 10:08
357 查看
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.
Nothing special as long as understand tree structure.
Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
Nothing special as long as understand tree structure.
bool isSameTree(TreeNode* p, TreeNode* q) { if(!p && !q) return true; if((!p && q) || (p && !q) || (p->val != q->val)) return false; return isSameTree(p->right, q->right) && isSameTree(p->left, q->left); }
相关文章推荐
- Android学习(声明)
- 从钉钉微应用定制化导航栏看如何实现Hybrid App开发框架
- numpy.array()
- 【理解题意】HDU2060Snooker
- 架设NFS服务器
- 针对抄袭和盗版的一点想法
- liunx bash 学习记录1
- Linux初始root密码设置
- 判断一个service是否启动
- nyoj 71
- c++ 大整数类
- H5仿吴亦凡参军H5
- 基于数字高程模型的冲沟提取
- ACM--湖南12年省赛--机器人的指令--CSU OJ--水
- skiing
- ZOJ 3927 Programming Ability Test
- SharePoint 工作流无法启动?
- nyoj 47
- ZOJ 3927 Programming Ability Test
- LeetCode 236. Lowest Common Ancestor of a Binary Tree