Chinaunix首页 | 论坛 | 博客
  • 博客访问: 254210
  • 博文数量: 170
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1709
  • 用 户 组: 普通用户
  • 注册时间: 2014-05-06 18:01
文章分类

全部博文(170)

文章存档

2016年(11)

2015年(130)

2014年(29)

分类: Java

2015-08-05 21:36:42

//Same Tree Total Accepted: 71830 Total Submissions: 173103 My Submissions Question Solution 
//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.
public class SameTree {


public static void main(String[] args) {
// TODO Auto-generated method stub


}
public boolean isSameTree(TreeNode p, TreeNode q) {
if(p==null&&q==null)
return true;
if(p==null||q==null)
return false;
if(p.val==q.val)
return isSameTree(p.left, q.left)&&isSameTree(p.right, q.right);
else
return false;
}


}

阅读(347) | 评论(0) | 转发(0) |
0

上一篇:Add Binary

下一篇:Unique Paths

给主人留下些什么吧!~~