[LeetCode] Same Tree
2015-09-30 01:31
239 查看
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; * struct TreeNode *left; * struct TreeNode *right; * }; */ bool isSameTree(struct TreeNode* p, struct TreeNode* q) { if(!p && !q) return true; if(!p || !q) return false; return p->val == q->val && isSameTree(p->left,q->left) && isSameTree(p->right,q->right); }
相关文章推荐
- QT5 学习之路03---开发环境搭建
- Kafka消息topic分区
- Kafka特性
- QT5 学习之路02---QT简介
- Kafka消息文件存储
- QT5 学习之路01---前言
- 哈夫曼树构造算法的正确性证明
- Hadoop2.x环境搭建
- 软件工程师关注的网站
- 代码规范之争——[个人Week2作业]
- python 缩进导致的问题
- getGenericSuperclass getSuperclass 区别
- 膝盖中了一箭之康复篇9-12周
- 计算机网络系列学习:Delay
- hdu 5493 (树状数组)
- Java JVM内存管理及垃圾回收
- hdu 5493 (树状数组)
- 研二:机遇(下)
- 学习笔记 - FileInputStream FileOutputStream文件拷贝
- Codeforces Round #322 (Div. 2) —— F. Zublicanes and Mumocrates