LintCode: Identical Binary Tree
C++
/**
* Definition of TreeNode:
* class TreeNode {
* public:
* int val;
* TreeNode *left, *right;
* TreeNode(int val) {
* this->val = val;
* this->left = this->right = NULL;
* }
* }
*/
class Solution {
public:
/**
* @aaram a, b, the root of binary trees.
* @return true if they are identical, or false.
*/
bool isIdentical(TreeNode* a, TreeNode* b) {
// Write your code here
if (a == NULL && b == NULL) {
return true;
}
if (a == NULL || b == NULL) {
return false;
}
if (a->val != b->val) {
return false;
}
return isIdentical(a->left, b->left) && isIdentical(a->right, b->right);
}
};
LintCode: Identical Binary Tree的更多相关文章
- [LintCode] Identical Binary Tree 相同二叉树
Check if two binary trees are identical. Identical means the two binary trees have the same structur ...
- CCI4.4/LintCode Balanced Binary Tree, Binary Tree, Binary Search Tree
Binary Tree: 0到2个子节点; Binary Search Tree: 所有左边的子节点 < node自身 < 所有右边的子节点: 1. Full类型: 除最下面一层外, 每一 ...
- [LintCode] Flatten Binary Tree to Linked List 将二叉树展开成链表
Flatten a binary tree to a fake "linked list" in pre-order traversal. Here we use the righ ...
- LintCode Balanced Binary Tree
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...
- lintcode:Binary Tree Postorder Traversal 二叉树的后序遍历
题目: 二叉树的后序遍历 给出一棵二叉树,返回其节点值的后序遍历. 样例 给出一棵二叉树 {1,#,2,3}, 1 \ 2 / 3 返回 [3,2,1] 挑战 你能使用非递归实现么? 解题: 递归程序 ...
- lintcode :Binary Tree Preorder Traversal 二叉树的前序遍历
题目: 二叉树的前序遍历 给出一棵二叉树,返回其节点值的前序遍历. 样例 给出一棵二叉树 {1,#,2,3}, 1 \ 2 / 3 返回 [1,2,3]. 挑战 你能使用非递归实现么? 解题: 通过递 ...
- LintCode: Flatten Binary Tree to Linked List
C++ Traverse /** * Definition of TreeNode: * class TreeNode { * public: * int val; * TreeNode *left, ...
- [LintCode] Invert Binary Tree 翻转二叉树
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...
- [LintCode] 619 Binary Tree Longest Consecutive Sequence III 二叉树最长连续序列 III
Given a k-ary tree, find the length of the longest consecutive sequence path. The path could be star ...
随机推荐
- lodash用法系列(5),链式
Lodash用来操作对象和集合,比Underscore拥有更多的功能和更好的性能. 官网:https://lodash.com/引用:<script src="//cdnjs.clou ...
- 解决iframe加载的内容有时显示有时不显示
在ASP.NET MVC项目中遇到了这样的一个问题,假设父页面有一个iframe <iframe id=" width="100%" height="10 ...
- Oracle JDBC连接服务名、SID和tnsnames.ora配置的多种方式
昨天,领导安排去新服务器上部署项目,给了我数据库地址,服务名称,端口,用户名和密码.结果数据库一直连接不上,日志中的错误提示是监听未找到SID,我才明白原来我jdbc.properties中需要的是S ...
- Tomcat 报 The valid characters are defined in RFC 7230 and RFC 3986
问题 24-Mar-2017 23:43:21.300 INFO [http-apr-8001-exec-77] org.apache.coyote.http11.AbstractHttp11Proc ...
- 都市侠盗第一季/全集Leverage迅雷下载
第一季 Leverage Season 1 (2008)看点:Nate Ford(蒂莫西·赫顿 Timothy Hutton 饰)曾当过保险调查员,为自己的老板挽回过数百万美元的损失,是个忠心耿耿的雇 ...
- [Web 前端] SuperAgent中文使用文档
cp from : https://blog.csdn.net/gebitan505/article/details/58585846 superagent是nodejs里一个非常方便的客户端请求代理 ...
- Mac下使用XLD转换无损音乐Ape
最近想要给音乐库增加一些音乐,下载了一些Ape格式的无损音乐,但是无法直接导入到iTunes中,必须经过其他工具转换成苹果的无损格式,XLD就是这样一款工具.XLD的下载和安装非常方便,直接将APP拖 ...
- Apache Jmeter 教程
Jmeter是一款优秀的开源测试工具, 是每个资深测试工程师,必须掌握的测试工具,熟练使用Jmeter能大大提高工作效率. 熟练使用Jmeter后, 能用Jmeter搞定的事情,你就不会使用LoadR ...
- perf使用示例2
perf使用示例2 性能调优工具如 perf,Oprofile 等的基本原理都是对被监测对象进行采样,最简单的情形是根据 tick 中断进行采样,即在 tick 中断内触发采样点,在采样点里判断程序当 ...
- JavaScript:Date 对象
ylbtech-JavaScript:Date 对象 1.返回顶部 Date 对象 Date 对象用于处理日期和时间. 创建 Date 对象的语法: var myDate=new Date() 注释: ...