LeetCode 100. Same Tree
2016-07-11 16:46
316 查看
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.
DFS题
Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
DFS题
class Solution { public: bool isSameTree(TreeNode* p, TreeNode* q) { if(!p && !q) return true; if(p && !q || !p && q) return false; if(isSameTree(p->left, q->left) && isSameTree(p->right, q->right) && p->val == q->val) return true; else return false; } };
相关文章推荐
- 【SSH视频】--- spring中的事务和hibernate中的session应用
- eclipse c++ 问题Launch failed,Binary not found和A program file was not specified in the launch configur
- 实训第三天--数字迷宫
- EventBus 3.0 使用介绍
- git简单操作
- Mybatis 执行批量插入 10W 4.8s
- MX、SPF记录查询的方法
- 使用第三方代码托管平台进行项目开发
- CF 241E Flights
- Cocos2dx报OpenGL error 0x0506错误
- iOS -- MVC的理解
- 网页版 treeview使用中遇到的问题
- WPF自动隐藏的消息框(鼠标放上去将一直显示,移开动画继续),提供normal和error两种边框。
- flask test_client设置cookies
- (4.2.33.1)Android上玩玩Hook(2):Cydia Substrate演练
- 关于UILabel
- levelDB源码学习——Arena(简单内存池)
- c 快速排序
- java调用R语言实现神经网络
- redis的pipeline测试分析