Given two binary trees, write a function to check if they areequal or not.
Two binary trees are considered equal if they are structurallyidentical and the nodes have the same value.

给定两个二叉树,写一个函数来检查它们是否是相等或不相等。

如果两个二叉树在结构上相同且节点具有相同的值,则它们被认为是相等的。

代码实现如下:

bool isSameTree(TreeNode *p, TreeNode *q) {if (p == NULL && q == NULL)return true;if ((p == NULL && q != NULL) || (p != NULL && q == NULL))return false;if (p->val != q->val)return false;bool left = isSameTree(p->left, q->left);bool right = isSameTree(p->right, q->right);return left && right;}

Given two binary trees, write a function to check if they areequal or not.相关推荐

  1. LeetCode之All Possible Full Binary Trees(Kotlin)

    问题: A full binary tree is a binary tree where each node has exactly 0 or 2 children. Return a list o ...

  2. Tweaked Identical Binary Trees - Medium

    Determine whether two given binary trees are identical assuming any number of 'tweak's are allowed. ...

  3. 17. Merge Two Binary Trees 融合二叉树

    [抄题]: Given two binary trees and imagine that when you put one of them to cover the other, some node ...

  4. LeetCode 617. Merge Two Binary Trees

    题目: Given two binary trees and imagine that when you put one of them to cover the other, some nodes ...

  5. C#LeetCode刷题之#617-合并二叉树​​​​​​​​​​​​​​(Merge Two Binary Trees)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4096 访问. 给定两个二叉树,想象当你将它们中的一个覆盖到另一个 ...

  6. (数据结构基础)Among the following threaded binary trees (the threads are represented by dotted curves),……

    当年学这些的时候真的是苦于没有人讲,现在复习考研,我会见到这种题就写下来,学弟学妹们欢迎点个关注,最近也在创业想实习的可以找我联系:没看懂的话是我表述有问题,欢迎指出和私戳. Among the fo ...

  7. Rosalind第88题:Counting Rooted Binary Trees

    Problem As in the case of unrooted trees, say that we have a fixed collection of  taxa labeling the  ...

  8. 617.Merge Two Binary Trees(合并两棵树)

    Given two binary trees and imagine that when you put one of them to cover the other, some nodes of t ...

  9. PyOpenGL报错OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit, check for

    在学计算机视觉时,增强现实需要导PyOpenGL,于是先在官网下载了PyOpenGL包 后报错,搜索解决办法直接pip install了一个镜像文件.依然报错OpenGL.error.NullFunc ...

最新文章

  1. Java虚拟机垃圾收集算法
  2. 简述安装Tsurugi Linux发行版
  3. 4行CSS实现【表格内容超过一行的部分,用省略号代替】【支持IE6】
  4. js 控制按钮点击后不可用(用于短信或者邮箱验证)
  5. Java:银行账户类
  6. C语言第五章实验二答案,《C语言程序设计》实验二 参考答案
  7. 代金券制作小程序秒代金券_微信小程序制作工具与方法
  8. 从零开始实现ASP.NET Core MVC的插件式开发(三) - 如何在运行时启用组件
  9. insert自动跳过存在数据_轻松入门mongo 数据库
  10. AdGuard广告拦截插件V3.6.6
  11. base-64 字符串中的无效字符。_查找字符串中连续不重复最长字符串和长度的方法...
  12. 随想录(公司程序员的九层楼)
  13. cmk聪明客机器人餐厅_晒晒我家85平新房,餐厅装修的太漂亮了,儿童房飘窗更实用!...
  14. BizTalk database lookup funcatoid DbConnectionString 设定问题有解了
  15. 平板电脑安装软件_手机象棋软件手机、平板、电脑三平台同时安装!学棋涨棋必备...
  16. java 时区 mysql 时区:时区在程序和数据库中的作用及其机制
  17. 共享软件作者怎样才能月入万
  18. 2014522420145238《信息安全系统设计基础》实验五
  19. 关于“‘c‘ argument has 1 elements, which is not acceptable for use with ‘x‘ with size 300“的解决办法
  20. 微信小程序使用promise 一次封装全部接口

热门文章

  1. VMware配置上限(Configuration Maximums)
  2. Maven学习总结(45)——Maven仓库、将本地Jar包安装到仓库、打可执行的Jar总结
  3. Java基础学习总结(79)——Java本地接口JNI详解
  4. PHP学习总结(5)——PHP入门篇之PHP字符串
  5. mysql 主从同步不一致_为什么mysql会经常出现主从同步不一致的情况
  6. 【都挺好】追求一生的科技住宅原来在这!
  7. 零配置简单搭建SpringMVC 项目
  8. 同一页面实现多个Tab选项卡功能
  9. Cocos2d BMFont解析
  10. 2月第三周各国家.NET域名排名Top10:中国第三