Identical Binary Tree
Check if two binary trees are identical. Identical means the two binary trees have the same structure and every identical position has the same value.
    1             1
   / \           / \
  2   2   and   2   2
 /             /
4             4
are identical.
    1             1
   / \           / \
  2   3   and   2   3
 /               \
4                 4
are not identical.
/**
* Definition of TreeNode:
* public class TreeNode {
* public int val;
* public TreeNode left, right;
* public TreeNode(int val) {
* this.val = val;
* this.left = this.right = null;
* }
* }
*/
public class Solution {
/**
* @param a, b, the root of binary trees.
* @return true if they are identical, or false.
*/
public boolean isIdentical(TreeNode a, TreeNode b) {
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);
}
}
Identical Binary Tree的更多相关文章
- [LintCode] Identical Binary Tree 相同二叉树
		
Check if two binary trees are identical. Identical means the two binary trees have the same structur ...
 - LintCode: Identical Binary Tree
		
C++ /** * Definition of TreeNode: * class TreeNode { * public: * int val; * TreeNode *left, *right; ...
 - Lintcode470-Tweaked Identical Binary Tree-Easy
		
470. Tweaked Identical Binary Tree Check two given binary trees are identical or not. Assuming any n ...
 - LEETCODE —— binary tree [Same Tree] && [Maximum Depth of Binary Tree]
		
Same Tree Given two binary trees, write a function to check if they are equal or not. Two binary tre ...
 - [算法专题] Binary Tree
		
1 Same Tree https://leetcode.com/problems/same-tree/ Given two binary trees, write a function to che ...
 - [数据结构]——二叉树(Binary Tree)、二叉搜索树(Binary Search Tree)及其衍生算法
		
二叉树(Binary Tree)是最简单的树形数据结构,然而却十分精妙.其衍生出各种算法,以致于占据了数据结构的半壁江山.STL中大名顶顶的关联容器--集合(set).映射(map)便是使用二叉树实现 ...
 - Leetcode 笔记 110 - Balanced Binary Tree
		
题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...
 - Leetcode, construct binary tree from inorder and post order traversal
		
Sept. 13, 2015 Spent more than a few hours to work on the leetcode problem, and my favorite blogs ab ...
 - [LeetCode] Find Leaves of Binary Tree 找二叉树的叶节点
		
Given a binary tree, find all leaves and then remove those leaves. Then repeat the previous steps un ...
 
随机推荐
- 2013337朱荟潼 Linux第四章读书笔记——进程调度
			
第4章 进程调度 0. 总结 调度:调度是一个平衡的过程.一方面,它要保证各个运行的进程能够最大限度的使用CP:另一方面,保证各个进程能公平的使用CPU. 调度功能:决定哪个进程运行以及进程运行多长时 ...
 - Daily Scrum 10.21
			
然后由于服务器端有变化,另外具体IDE已经确定,接下来对已经分配下去的任务做些细节补充: 10.20日晚所有人必须完成AS的配置,统一版本为1.3.2,安卓版本为4.4.0,可视化界面手机为Nexus ...
 - 对MP4一些概念的理解
			
首先,对视频一些基本概念的理解: I帧:i帧又称为内编码帧,是一种自带全部信息的独立帧,可独立解码,可理解为一张静态图片,视频序列中的第一个帧始终是i帧,因为它是关键帧. P帧:P帧又称为帧间预测编码 ...
 - 贝叶斯先验解释l1正则和l2正则区别
			
这里讨论机器学习中L1正则和L2正则的区别. 在线性回归中我们最终的loss function如下: 那么如果我们为w增加一个高斯先验,假设这个先验分布是协方差为 的零均值高斯先验.我们在进行最大似然 ...
 - jmeter 获取执行脚本的路径
			
需求:向jmeter.jmx 的路径下 写日志 : import org.apache.jmeter.services.FileServer; import com.bzj.utils.*; Stri ...
 - JIRA部署破解和confluence整合
			
JIRA是一个项目跟踪管理工具,帮助团队创建计划任务.构建并发布优秀的产品.全球成千上万的团队选择JIRA,用JIRA来捕获.组织管理缺陷.分配任务,跟踪团队的活动.不论在桌面PC还是移动终端设备上, ...
 - Java获取当前运行方法所在的类和方法名
			
很简单,直接看代码: public void showClassAndMethod() { System.out.println(this.getClass().getSimpleName() + & ...
 - DataSet和实体类的相互转换
			
最近做WInfrom项目,对表格和控件的数据绑定非常喜欢用实体类对象来解决,但是绑定以后 又怎么从控件中拿到实体类或者转换为datatable 或者dataset呢 经过在网上的搜索以及自己的改进 完 ...
 - CF 1070J Streets and Avenues in Berhattan
			
DP的数组f其实开得不够大,应该开200000,但是它在cf上就是过了... 题意是把一堆字母分别分配到行和列. 分析一下,答案实际上只和n行中和m列中每种字母分配的个数有关.而且答案只和" ...
 - 【大数据】SparkSql学习笔记
			
第1章 Spark SQL概述 1.1 什么是Spark SQL Spark SQL是Spark用来处理结构化数据的一个模块,它提供了2个编程抽象:DataFrame和 DataSet,并且作为分布式 ...