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. ios与js交互获取webview元素和赋值

    使用webview的stringByEvaluatingJavaScriptFromString的方法交互,直接提供实例. 下载:http://download.csdn.net/detail/hey ...

  2. cordova热更新插件调试

    有更新www目录内容后,首先sencha app build,然后进入 cordova目录 运行 cordova-hcp build, 然后查看 chcp.json文件时间,然后压缩cordova目录 ...

  3. nginx +uwsgi + django配置

    一 安装 nginx 二 安装 uwsgi  ,pip install uwsgi 三 配置nginx 打开 nginx.conf文件, location / { # root html; # ind ...

  4. Scala 中Array,List,Tuple的差别

    尽管学了一段时间的Scala了,可是总认为基础不是太扎实,还有非常多的基础知识比較模糊.于是近期又打算又一次学习基础. Scala中的三种集合类型包含:Array,List,Tuple.那么究竟这三种 ...

  5. Mockito使用指南

    转载请标明出处:http://blog.csdn.net/shensky711/article/details/52771493 本文出自: [HansChen的博客] mock和Mockito的关系 ...

  6. 【MVC2】发布到IIS7.5上后Session为null

    MVC2代码「Session.IsNewSession」在VS中可以正常执行,发布到IIS7.5上之后Session为null导致出错. if (Session.IsNewSession) { ... ...

  7. shell中sed命令

    sed -i '/cd ${LDIR_DEST}\/webextend\/pc && ln -s \/hard\/www_winclient\/bboxpc.exe ./a\ \tcd ...

  8. Shell脚本之:while

    while循环用于不断执行一系列命令,也用于从输入文件中读取数据:命令通常为测试条件.其格式为: while command do Statement(s) to be executed if com ...

  9. Oracle 中session和processes的初始设置

    http://blog.163.com/succu/blog/static/193917174201252911727149/ 1.sessions   在初始化参数所设定的限制中,最为人所知的估计就 ...

  10. EMC机理------串扰

    转:电子工程师不得不知道的EMC机理------串扰(韬略科技EMC) 串扰是信号完整性中最基本的现象之一,在板上走线密度很高时串扰的影响尤其严重.我们知道,线性无缘系统满足叠加定理,如果受害线上有信 ...