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 ...
随机推荐
- 在ASP.NET MVC下扩展一个带验证的RadioButtonList
在ASP.NET MVC4中,HtmlHelper为我们提供了Html.RadioButton()方法用来显示Radio Button单选按钮.如果想显示一组单选按钮,通常的做法是遍历一个集合把每个单 ...
- Codeforces Round #131 Div1 B
Problem 给出Ai(i∈[0,9]).表示每一个数字至少须要出现多少次.问有多少个数满足下面三个条件:1. 数至多有N位:2. 数不含有前导0:3. 每一个数 i 出现的次数不少于Ai(mod ...
- nodeJS 相关开源项目
摘要:NodeJS是一个服务器端JavaScript解释器,它将改变服务器应该如何工作的概念.它的目标是帮助程序员构建高度可伸缩的应用程序,编写能够处理数万条同时连接到一个(只有一个)物理机的连接代码 ...
- 每天一个linux命令-ls命令
查看统计当前目录下文件的个数,包括子目录里的. ls -lR| grep "^-" | wc -l[喝小酒的网摘]http://blog.hehehehehe.cn/a/12311 ...
- Java实现bt文件下载、制作、解析、磁力链接
首先torrent里面肯定携带的有一些信息,所以就需要我们来解析这些信息. 我们这里做多文件制作torrent,所以首先要针对每一个文件建一个实体类 import java.util.List; pu ...
- 自定义View,随着手指运动的小球
这个实例是自定的view的初步介绍,要设计的是一个随着手指运动的小球.原理是随时获取手指的坐标,然后在这个坐标上面实时改变自定义view的坐标.这个view仅仅是画了一个圆形而已. 自定义的view ...
- [Web 前端] 前端频道之团队维护、聚合、订阅
cp from :https://blog.csdn.net/ivan820819/article/details/78885404 国内 腾讯 ISUX 腾讯全端 AlloyTeam 奇舞周刊 阿里 ...
- main函数的参数argc和argv
版权声明:本文为博主原创文章,转载请注明CSDN博客源地址!共同学习,一起进步~ https://blog.csdn.net/Eastmount/article/details/20413773 该篇 ...
- Unexpected identifier in composer-common/lib/cardstore/businessnetworkcardstore.js:54
c错误描述 Unexpected identifier in composer-common/lib/cardstore/businessnetworkcardstore.js:54 yo hyper ...
- [转]Linux的SOCKET编程详解
From : http://blog.csdn.net/hguisu/article/details/7445768 1. 网络中进程之间如何通信 进 程通信的概念最初来源于单机系统.由于每个进程都在 ...