[题目]

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) {if(null == p && null == q) return true;if(null != p && null != q){return (p.val == q.val && isSameTree(p.left,q.left) && isSameTree(p.right,q.right));}else{return false;}}
}

转载于:https://www.cnblogs.com/zzchit/p/5778166.html

[LeetCode] NO. 100 Same Tree相关推荐

  1. LeetCode 100. Same Tree

    LeetCode 100. Same Tree Solution1: 这种弱智题提交这么多次... /*** Definition for a binary tree node.* struct Tr ...

  2. LeetCode Top 100 Liked 点赞最高的 100 道算法题

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:刷题顺序,刷题路径,好题,top100,怎么刷题,Leet ...

  3. LeetCode: 106. Construct Binary Tree from Inorder and Postorder Traversal

    题目 Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume ...

  4. LeetCode 110 Balanced Binary Tree 平衡二叉树

    LeetCode 110 Balanced Binary Tree Given a binary tree, determine if it is height-balanced. For this ...

  5. LeetCode 105. Construct Binary Tree from Preorder and Inorder Traversal 由前序和中序遍历建立二叉树 C++...

    LeetCode 105. Construct Binary Tree from Preorder and Inorder Traversal 由前序和中序遍历建立二叉树 C++ Given preo ...

  6. LeetCode 106. Construct Binary Tree from Inorder and Postorder Traversal

    LeetCode 106. Construct Binary Tree from Inorder and Postorder Traversal Solution1:我的答案 仿照105题写的答案 / ...

  7. LeetCode 105. Construct Binary Tree from Preorder and Inorder Traversal

    LeetCode 105. Construct Binary Tree from Preorder and Inorder Traversal 本博客转载自:http://www.cnblogs.co ...

  8. LeetCode 110. Balanced Binary Tree

    LeetCode 110. Balanced Binary Tree 本博客参考自:http://www.cnblogs.com/grandyang/p/4045660.html Solution1: ...

  9. LeetCode: 173. Binary Search Tree Iterator

    LeetCode: 173. Binary Search Tree Iterator 题目描述 Implement an iterator over a binary search tree (BST ...

最新文章

  1. fedora12安装小企鹅输入法
  2. RxJava 参考文档
  3. nginx 1.4.3能直接升到1.8.1吗
  4. 沈梦辰回应闲鱼卖假货事件:负责到底 不做一锤子买卖
  5. Javabean的理解(通过javabean的部分程序)
  6. IJCAI 2019 | 为推荐系统生成高质量的文本解释:基于互注意力机制的多任务学习模型...
  7. flex 常用正则验证举例
  8. php生成迷宫图片,PHP实现基于回溯法求解迷宫问题的方法详解
  9. 计算机数据及报告备份记录表,数据处理-泉州市第六次全国人口普查-专题专栏-泉州统计信息网...
  10. python词云图背景_python词云图之WordCloud
  11. WindwosServer系统一些设置【网卡驱动修复】【安装UWP应用】【服务器管理取消开机自启动】
  12. 手机WIFI传文件到局域网服务器,局域网内手机和电脑怎么实现无线传输文件?
  13. 使用TextPaint实现自由加粗字体:BoldTextView,支持中粗
  14. Python人工智能完整学习路线
  15. 谭浩强C语言学习day1
  16. VS 2019 C++ 如何在非控制台程序中打开控制台
  17. 远程ARM设备Xavier方法——ZeroTier+nomachine
  18. Web兼容性测试的要点
  19. coding期间遇到的bug记录
  20. ESP32学习笔记(34)——BLE一主多从连接

热门文章

  1. 生成随机字符串,包含英文和数字,可指定长度
  2. EJB3.0 定时服务:Timer Service
  3. php 第三方DB库NOTORM
  4. [转载]使用RoboCopy 命令
  5. 4G EPS 中建立 eNB 与 MME 之间的 S1 连接
  6. C51汇编伪指令 CSEG DSEG
  7. Spring思维导图,让Spring不再难懂(aop篇)
  8. 某油企产成品标准成本估算逻辑
  9. shell字符串截取方法
  10. More about Tair (NoSql)