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 ...
随机推荐
- python交互模式下cp65001异常
unknown encoding: cp65001异常 python安装后进入命令行交互模式,输入任何代码都报unknown encoding: cp65001异常 需要将编码(UTF-8)修改为 简 ...
- MATLAB axes
本帖由MATLAB技术论坛(http://www.matlabsky.com)原创,更多精彩内容参见http://www.matlabsky.com axes ★★★★★ 功能 创建坐标系图形对象 语 ...
- [转][C/C++]函数名字修饰(Decorated Name)方式
1.C/C++函数修饰名: 对于我们的C/C++源程序而言,函数名只是函数的一小部分,函数还有调用方式(参数入栈方式).返回值类型.参数个数和各参数类型等信息,对于C++类成员函数,还有更多信息.这些 ...
- iOS闪烁效果工具 GlitchLabel
GlitchLabel 用于给文字添加闪烁效果,效果图如下: 开发环境: iOS 7.0+ Swift 2.2 Xcode 7 示例代码:https://www.yuedecaifu.com 1 2 ...
- Mac下SVN服务器环境的搭建和配置(除展示图片外,所有命令在Linux/Unix下适用)
这几天领导没有安排工作,闲着没事就想把自己这两年做iOS开发时感觉知识有欠缺的地方想好好深入地补习一下,昨天和今天就计划好好学习下SVN和git的从创建和到原理,到命令,到界面的使用.一不小心被另一领 ...
- python3控制路由器--使用requests重启极路由.py
代码写了相应的注释,以后再写成可以方便调用的模块. 用fiddler抓包可以看到很多HTTP头,经过尝试发现不是都必须的. 'Upgrade-Insecure-Requests':1,#必要项,值为1 ...
- EasyUI 验证框使用方法
使用过程中的一积累,备查. EasyUI 验证框使用方法://***************************missingMessage:未填写时显示的信息validType:验证类型见下示例 ...
- Why am I getting an error converting a Foo** → const Foo**?
Because converting Foo** → const Foo** would be invalid and dangerous. C++ allows the (safe) convers ...
- 在.net中实现在textbox中按ctrl+enter进行数据的提交
textbox.Attributes.Add("onKeydown", "if(event.ctrlKey&&event.keyCode == 13){d ...
- php大力力 [018节]如何联系大力力
有事儿就注册博客园,给我发 博客园站内的 短消息呗,唉,没有人联系我呀,啦啦啦,爱我爱我,快点爱我 2015-08-26 php大力力018.如何联系大力力