leetcode 100 Same Tree ----- java
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.
判断两棵树是否相同。
很简单。递归。
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public boolean isSameTree(TreeNode p, TreeNode q) { return getResult(p,q);
}
public boolean getResult(TreeNode p,TreeNode q){
if( p == null && q == null )
return true;
else if( p == null || q == null)
return false; if( p.val != q.val)
return false; return getResult(p.left,q.left)&&getResult(p.right,q.right); }
}
leetcode 100 Same Tree ----- java的更多相关文章
- LeetCode 100. Same Tree (判断树是否完全相同)
100. Same Tree Given two binary trees, write a function to check if they are the same or not. Two bi ...
- leetcode 100. Same Tree、101. Symmetric Tree
100. Same Tree class Solution { public: bool isSameTree(TreeNode* p, TreeNode* q) { if(p == NULL &am ...
- Java [Leetcode 100]Same Tree
题目描述: Given two binary trees, write a function to check if they are equal or not. Two binary trees a ...
- Java for LeetCode 100 Same Tree
Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...
- LeetCode 100. Same Tree (相同的树)
Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...
- [LeetCode] 100. Same Tree 相同树
Given two binary trees, write a function to check if they are the same or not. Two binary trees are ...
- leetcode 100. Same Tree
Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...
- leetcode 101 Symmetric Tree ----- java
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...
- [Leetcode]100. Same Tree -David_Lin
Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...
随机推荐
- 采用EntLib5.0(Unity+Interception+Caching)实现项目中可用的Caching机制
看了园子里很多介绍Caching的文章,多数都只介绍基本机制,对于Cache更新和依赖部分,更是只简单的实现ICacheItemRefreshAction接口,这在实际项目中是远远不够的.实际项目中, ...
- 【STL】-priority_queue的用法
初始化: priority_queue<int> maxPQ; priority_queue<int,vector<int& ...
- HTTP Status 404 - No result defined for action com.csdhsm.struts.action.LoginAction and result error
智商拙计的问题,没有找到为类LoginAction和error找到定义,然后重新去struts.xml去看,我类个去,我居然把result写成了ERROR <result name=" ...
- FG模型
一直没搞懂CvBGStatModel和CvFGDStatModel有什么区别.CvBGStatModel模型的创建用cvCreateGaussianBGModel,CvFGDStatModel模型的创 ...
- SQL语句查询所耗时间与效能的语句
1)SQL查询所耗时间语句 原理:记录当前时间1,执行SQL语句,记录当前时间2,显示时间2与时间1的差. 由于第一次执行的所耗时间为真实时间,之后会保存在缓存中,所以第二次之后的查询所耗时间都会比第 ...
- Google 宣布支持中文邮箱地址
Gmail 宣布,即日起开始支持非拉丁字符邮箱地址.也就是说,我们可以在 Gmail 中针对中文邮箱地址发送和接收邮件了. 全世界母语是拉丁字母语言的人类不超过全人类总数的一半,母语是英语的人数更少. ...
- 《JAVA学习笔记(14-10---14-11抽象类)》
[14-10]面向对象-抽象类的产生 /* 描述狗,行为,吼叫. 描述狼,行为,吼叫. 发现他们之间有共性,可以进行向上抽取. 当然是抽取他们的所属共性类型,犬科. 犬科这类事物,都具备吼叫行为,但是 ...
- POJ 2887 Big String (块状数组)
题意:给一个字符串(<=1000000)和n个操作(<2000),每个操作可以在某个位置插入一个字符,或者查询该位置的字符.问查询结果. 思路:块状数组. 如果将原来的字符串都存在一起,每 ...
- (转) mysql的连接,创建账号,修改密码
原文:http://blog.chinaunix.net/uid-20749043-id-1878306.html mysql的连接,创建账号,修改密码 2008-10-13 15:31:29 分类 ...
- (spring-第14回【IoC基础篇】)国际化信息
国际化又称为本地化. 当你把手机的language由中文切换到英文时,你的微信也相应改用英语,这就是i18n国际化.一般来说,应用软件提供一套不同语言的资源文件,放到特定目录中,应用根据不同语言的操作 ...