Leetcode55: Same Tree
2015-09-14 14:43
246 查看
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.
Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
/** * 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 true; else if(p == NULL || q == NULL) return false; return p->val == q->val && isSameTree(p->left, q->left) && isSameTree(p->right, q->right); } };
相关文章推荐
- 花生壳端口映射实例说明
- icc链接gcc库
- oracle数据库中使用sql将clob转化为字符串
- dup,dup2函数【转】
- RMAN异机恢复快速参考
- NGUI判断是否点击到UI控件
- iOS中nil,Nil,NULL之间的区别
- linux配置ant
- tcp/ip详解学习(一)
- Win10 只有Edge无法上网的解决方法
- Android之HttpClient 和HttpResponse 小结
- 一个简单MVC5 + EF6示例分享
- Android五大布局的使用及其它
- 最流行的android组件及开源大全
- 十进制转换为任意进制 java实现
- asp.net中弹框提示的几种写法
- hdu 5074 相邻的和最大dp
- pb datawindow的用法
- 安卓 apk反编译教程
- xem和virsh常用命令