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 ...
随机推荐
- debug实战:进程Hang+High CPU
最近几周都在解决程序不稳定的问题,具体表现为程序(多进程)时不时的Hang住,同时伴随某个进程的High CPU.跟踪下来,基本都是各种死锁引起的.这里选取一个典型的场景进行分析. 1.抓dump分析 ...
- VisualSVN SERVER的安装和使用
SVN Server安装 Subversion是优秀的版本控制工具,其具体的的优点和详细介绍,这里就不再多说.下载的网址是:http://subversion.apache.org/packages. ...
- 酷狗音乐盒缓存文件夹KuGouCache的设置方法
1.每次一打开酷狗总能在E盘里找到这个 KuGouCache 文件夹 ,是自动生成的MV缓存文件 .按照常规 ,可以修改这个文件的办法是 找到C盘里的:用户\administrator\AppDate ...
- GoldenGate中使用strcat和strext进行数据转换
在OGG中可以对源字段的内容进行合并或拆分,从而实现类似于“ETL”的功能.strcat(s1,s2,s3,,,):用于合并字串:strext(str, start, end):用于获取指定位置的字串 ...
- 实用的WPF Xml的简易读写类以及用法示例
转自:http://www.silverlightchina.net/html/study/WPF/2012/0808/17980.html 最近真是写博客写的不可收拾,今天再来一篇. 因为做一些程序 ...
- tip use view.isineditmode() in your custom views to skip code when shown in eclipse
tip use view.isineditmode() in your custom views to skip code when shown in eclipse
- HttpClient -- 血的教训
HttpClient -- 血的教训 千万别用httpClient 不支持httpVersion2.0 因为这个导致项目重做
- codeforces round367 div2.C (DP)
题目链接:http://codeforces.com/contest/706/problem/C #include<bits/stdc++.h> using namespace std; ...
- 为什么有的代码要用 base64 进行编码
一.1.传输信道只支持ASCII字符,不方便传输二进制流的场合. 2.含有非ASCII字符,容易出现编码问题的场合. 3.简易的掩人耳目.至少非开发人一眼看不出来是啥. 二.Base64主要用于将不可 ...
- Unity3d各平台资源路径文件夹
之前一直是PC项目,公司终于考虑移动平台了,但是试验了几把,感觉移动平台资源管理路径还是有很多隐藏的注意事项. 比如在PC上可以做到随便读写,但是在移动平台就涉及到权限问题. 看到小伙伴的总结,还是要 ...