Same Tree
2015-08-04 11:02
344 查看
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.
Two binary trees are considered equal if they are structurally identical and the nodes
have the same value.
public class Solution { public boolean isSameTree(TreeNode p, TreeNode q) { if(p==null&&q==null) return true; else if(p==null||q==null) return false; return p.val==q.val&&isSameTree(p.left,q.left)&&isSameTree(p.right,q.right); } }
相关文章推荐
- linux 下编译安装Qt
- 微信服务号 网站服务器不能直接获取用户session的问题
- Linux cronolog
- 实用小技巧(一)
- try
- Struts2组合spring
- 0-1排序引理
- 南邮 OJ 1095 奇特的图形
- 判断js是否被禁用
- 常用做action recognition 的数据集介绍
- C++中friend的使用(friend function and friend class)
- 软件测试博客较好的网址(供参考)
- 【转】一个非常标准的Java连接Oracle数据库的示例代码
- *Delphi多线程的OnTerminate属性(附加一个关于临界区线程同步的例子)
- 解决Python传递中文参数的问题
- 南邮 OJ 1094 蛇形填数
- AD 对象信息查询利器---ADExplorer
- 基础学习笔记之opencv(2):haartraining前将统一图片尺寸方法
- Apache Portable Runtime (APR) based Native library for Tomcat
- iOS开发 字符串转换成字典