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 ...
随机推荐
- 房子里的K2 BPM业务流程管理
房…子这件事上,尴尬实在太多. ಥ_ಥ 职场新人,租房很尴尬: 未婚男女,婚房很尴尬: 有下一代的,学区房很尴尬: 耄耋之年,养老房很尴尬... ▽ 甭管买房.租房.装修.设计,关于房子的尴尬事,三天 ...
- 离线安装chrome插件
1. 先百度下载自己要安装的chrome插件,比如:Postman 和 Json View. 2.下载完应该得到的是扩展名为crx的文件. 比如: Postman-REST-Client_v0.8.4 ...
- 获取Android系统的版本号
int currentVersion = android.os.Build.VERSION.SDK_INT;
- 程序中double类型的数输出为什么要用lf
在c89和c++中double的输入和输入输出都用%lf 在c99中,double的输出必须用%f,而输入要用%lf oIER一般使用c++,所以输出直接%lf即可.
- form表单select联动
下拉列表:二级联动菜单 Select对象的常用属性 options[]:返回所有option组成的一个数组: name:名称 value:option的value的值 length:设置或读取opti ...
- STL中的lower_bound和upper_bound的理解
STL迭代器表述范围的时候,习惯用[a, b),所以lower_bound表示的是第一个不小于给定元素的位置 upper_bound表示的是第一个大于给定元素的位置. 譬如,值val在容器内的时候,从 ...
- C/C++ memmove 和 memcpy
这两个函数用于拷贝字符串或者一段连续的内存,函数原型: void * memcpy ( void * destination, const void * source, size_t num ); v ...
- 三、XML编程(CRUD)
DOM:W3C标准SAX:simple API for XMLDOM解析会把整个文档读入内存变成一个对象,会把标签变为Element对象,会把文本变成Text对象,会把属性变为Attribute对象, ...
- UID 修改 & UID 锁死修复
首先是UID修改的问题,只要卡是UID卡,就都可以修改UID,首先读卡器连接电脑,卡片放到读卡器上. 然后我们要用一个工具,UID207.打开UID207.exe,点Initialize,初始化. 然 ...
- 什么php?
PHP是一种开源的通用计算机脚本语言,尤其适用于网络开发并可嵌入HTML中使用.PHP的语法借鉴吸收了C语言.Java和Perl等流行计算机语言的特点,易于一般程序员学习.PHP的主要目标是允许网络开 ...