leetcode 100. Same Tree(递归)
2016-04-30 03:47
405 查看
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==nullptr&&q==nullptr){ return true; } else if(p==nullptr||q==nullptr){ return false; } if(p->val==q->val){ return isSameTree(p->left,q->left)&&isSameTree(p->right,q->right); } return false; } };
相关文章推荐
- MyBatis学习(一) MyBatis入门
- 一些CMS网站系统漏洞,练手用(持续更新)
- leetcode 292. Nim Game
- HDU 2022 海选女主角(水题)
- HDU 2021 发工资咯:)(暴力枚举)
- mysql5.7bug trace与查询计划不符合
- 分区表
- leetcode - wigglesort
- 编程模拟自然(七):力学矢量与牛顿定律
- 【Swift学习】Swift编程之旅---方法(十五)
- 路由配置:理解secondary ip address
- [leetcode] 4. Median of Two Sorted Arrays 解题报告
- C语言 字符串匹配问题,KMP函数-失配函数
- ios - 自动布局框架编写(更多功能完善中)
- Formal Languages and Compilers-LL(1),FIRST and FOLLOW
- HDU 2020 绝对值排序(排序)
- 海量数据存储之Key-Value存储简介
- 海量数据存储之Key-Value存储简介
- 大数据时代的 9 大Key-Value存储数据库
- HDU 2019 数列有序!(水题)