Lintcode 469. 等价二叉树

-----------------------------------------------
AC代码:
/**
* 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;
else if(a==null || b==null) return false;
else if(a.val!=b.val) return false;
return isIdentical(a.left,b.left) && isIdentical(a.right,b.right);
}
}
题目来源: http://www.lintcode.com/zh-cn/problem/identical-binary-tree/
Lintcode 469. 等价二叉树的更多相关文章
- lintcode:等价二叉树
等价二叉树 检查两棵二叉树是否等价.等价的意思是说,首先两棵二叉树必须拥有相同的结构,并且每个对应位置上的节点上的数都相等. 样例 1 1 / \ / \ 2 2 and 2 2 / / 4 4 就是 ...
- LintCode2016年8月8日算法比赛----等价二叉树
等价二叉树 题目描述 检查两棵二叉树是否等价.等价意思是说,首先两棵二叉树必须拥有相同的结构,并且每个对应位置上的节点上的数据相等. 样例 1 1 / \ / \ 2 2 and 2 2 / / 4 ...
- LeetCode951-翻转等价二叉树
问题:翻转等价二叉树 我们可以为二叉树 T 定义一个翻转操作,如下所示:选择任意节点,然后交换它的左子树和右子树. 只要经过一定次数的翻转操作后,能使 X 等于 Y,我们就称二叉树 X 翻转等价于二叉 ...
- [Swift]LeetCode951. 翻转等价二叉树 | Flip Equivalent Binary Trees
For a binary tree T, we can define a flip operation as follows: choose any node, and swap the left a ...
- Leetcode951. Flip Equivalent Binary Trees翻转等价二叉树
我们可以为二叉树 T 定义一个翻转操作,如下所示:选择任意节点,然后交换它的左子树和右子树. 只要经过一定次数的翻转操作后,能使 X 等于 Y,我们就称二叉树 X 翻转等价于二叉树 Y. 编写一个判断 ...
- LintCode_469 等价二叉树
题目 检查两棵二叉树是否等价.等价的意思是说,首先两棵二叉树必须拥有相同的结构,并且每个对应位置上的节点上的数都相等. 样例 1 1 / \ / \ 2 2 and 2 2 / / 4 4 就是两棵等 ...
- Lintcode 175. 翻转二叉树
-------------------- 递归那么好为什么不用递归啊...我才不会被你骗...(其实是因为用惯了递归啰嗦的循环反倒不会写了...o(╯□╰)o) AC代码: /** * Definit ...
- Lintcode 375.克隆二叉树
-------------------------- 水题 AC代码: /** * Definition of TreeNode: * public class TreeNode { * public ...
- lintcode:将二叉树拆成链表
题目 将一棵二叉树按照前序遍历拆解成为一个假链表.所谓的假链表是说,用二叉树的 right 指针,来表示链表中的 next 指针. 注意事项 不要忘记将左儿子标记为 null,否则你可能会得到空间溢出 ...
随机推荐
- 【JavaWeb】SSM+SpringSecurity+EhCache+JCaptcha 完整Web基础框架(六)
Showings 我个人的项目,当前不断地在更新. 我希望做成一个好项目,同时,也是在锻炼自己的技术. 在项目中发现问题,学习知识,是比较可取的一条路子. 这样学习到的知识,虽然分散,但是都很实用,而 ...
- php采集远程图片
- python学习笔记(二)
(一)模块打包 ---> 注:suba和subb文件夹下的__init__.py文件,即使为空,也必须存在 "setup.py" from distut ...
- EmployeeTest
package fourthf; public class EmployeeTest { public static void main(String[] args) { // TODO Auto-g ...
- ubuntu下非root用户下获得使用wireshark的权限
在非root用户下不能使用wireshark用来抓包,所以需要进行以下操作: sudo groupadd wireshark sudo chgrp wireshark /usr/bin/dumpcap ...
- ubuntu安装/卸载mysql
1.安装mysql root@openstack001:/tmp# apt-get install mysql-server Reading package lists... Done Buildin ...
- LibreOffice去重复数据
菜单:数据--更多筛选---标准筛选 点开“选项”,勾上“无重复值”. 然后还可以把结果复制到其它单元格.
- ubuntu 12.04 sever下安装jre
具体步骤如下: 首先打开http://www.java.com/en/download/linux_manual.jsp?locale=en 选择你想下载的版本,此处我选择的是jre-7u25-lin ...
- php SESSION跨域问题
这段时间随着项目功能的扩展,慢慢接触到了跨域方面的知识,遇到的更多的问题也是前端与后端交互的时候跨域问题.关于js跨域的问题我会在其他分类里面写.这里记录我今天遇到的php session跨域问题 当 ...
- STL
STL qsort intcompare(constvoid*arg1,constvoid*arg2){ return(*(int*)arg1<*(int*)arg2)?-1: (*(int*) ...