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.

解题思路:

JAVA实现如下:

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

Java for LeetCode 100 Same Tree的更多相关文章

  1. Java for LeetCode 107 Binary Tree Level Order Traversal II

    Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...

  2. 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 ...

  3. leetcode 100. Same Tree、101. Symmetric Tree

    100. Same Tree class Solution { public: bool isSameTree(TreeNode* p, TreeNode* q) { if(p == NULL &am ...

  4. leetcode 100 Same Tree ----- java

    Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...

  5. Java [Leetcode 100]Same Tree

    题目描述: Given two binary trees, write a function to check if they are equal or not. Two binary trees a ...

  6. LeetCode 100. Same Tree (相同的树)

    Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...

  7. [LeetCode] 100. Same Tree 相同树

    Given two binary trees, write a function to check if they are the same or not. Two binary trees are ...

  8. Java for LeetCode 199 Binary Tree Right Side View

    Given a binary tree, imagine yourself standing on the right side of it, return the values of the nod ...

  9. Java for LeetCode 145 Binary Tree Postorder Traversal

    Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary ...

随机推荐

  1. 聊聊、Zookeeper 客户端 ZkClient

    [ZkClient]  ZkClient 是 GitHub 上一个开源的客户端,如果我们用 Maven 来管理工程,则引用如下. <dependency> <groupId>o ...

  2. 如何让自己的程序支持iPhone5–RetinaImages

    我们知道如果想让程序的启动图像能够适应iPhone5(640X1136),那么我们需要把启动的图像命名以“-568h@2x”结尾的图片,那 么是不是程序中用到的所有图片都可以用这样的方式来命名,以适合 ...

  3. 细数国外SEO,SEM,SNS资深博客论坛和站点

    如果你有时间,如果有英语还不错能看懂国外的推广营销知识,如果你想做个实战者,如果你想比别人多领先,如果你爱好这个推广行业,如果你不想做河塘里的小鱼,如果····请一个个的看以下的站点,个人觉得会给你另 ...

  4. maven setting.xml 配置(有效)

    <?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://mav ...

  5. 手机APP脚本录制(LoadRunner 12)

    最近因项目需要,研究了下手机APP脚本录制方法,有需要的童鞋可参考使用! 方法1: 在手机网络中设置网络代理,使用LR12选择Mobile Application – HTTP/HTML协议中代理录制 ...

  6. java 环境变量配置 Mac

    大家在windows里面配置JDK环境变量很容易,但是如果要在mac里面配置JDK环境变量和windows里面有所不同,具体如下: 第一: mac OS里面自带jdk,不过是1.6的版本,现在很多人使 ...

  7. mysql使用mysqldump 与 mysqlimport进行数据库迁移

    1.导入数据库 1)source source /home/platvt/product/pc2_create_tables.sql 2)mysqlimport 使用mysqlimport导入数据: ...

  8. TP框架模板中ifelse

    {if $_username}<ul class="afterLogin">    <li class="username"><a ...

  9. Python Flask 在Sina App Engine (SAE)上安家

    早就听说了Python的大名,随着的编程语言的理解加深,越发认为动态语言的威力--真大呀. 趁这段时间不忙,我也用Python写了一个应用,而且将其部署到Sina App Engine (SAE).S ...

  10. 看完这篇还不会自定义 View ,我跪搓衣板

    自定义 View 在实际使用的过程中,我们经常会接到这样一些需求,比如环形计步器,柱状图表,圆形头像等等,这时我们通常的思路是去Google 一下,看看 github 上是否有我们需要的这些控件,但是 ...