判断两棵二叉树是否相等

/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
bool isSameTree(TreeNode* p, TreeNode* q) {
if ((p==NULL&&q!=NULL)||(q==NULL&&p!=NULL)) return false;
if (p==NULL && q==NULL) return true; if (p->val != q->val) return false;
else return isSameTree(p->left,q->left)&&isSameTree(p->right,q->right);
/*
if (p->left != NULL && q->left != NULL){
if (p->left->val != q->left->val) return false;
isSameTree(p->left,q->left);
}
if (p->right != NULL && q->right != NULL){
if (p->right->val != q->right->val) return false;
isSameTree(p->right,q->right);
}
//一个大错特错的递归…………
*/
//return true;
}
};

【easy】100. Same Tree的更多相关文章

  1. 【LeetCode】100. Same Tree 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 [LeetCode] 题目地址:https:/ ...

  2. 【LeetCode】100 - Same Tree

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

  3. 【easy】257. Binary Tree Paths 二叉树找到所有路径

    http://blog.csdn.net/crazy1235/article/details/51474128 花样做二叉树的题……居然还是不会么…… /** * Definition for a b ...

  4. 【easy】107. Binary Tree Level Order Traversal II 按层输出二叉树

    按层输出二叉树,广度优先. 3 / \ 9 20 / \ 15 7 [ [15,7], [9,20], [3] ] /** * Definition for a binary tree node. * ...

  5. 【easy】101. Symmetric Tree

    判断一棵二叉树是否对称 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left ...

  6. 【LeetCode】100. Same Tree (2 solutions)

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

  7. 【Leetcode】【Easy】Balanced Binary Tree

    Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...

  8. 606. Construct String from Binary Tree 【easy】

    606. Construct String from Binary Tree [easy] You need to construct a string consists of parenthesis ...

  9. 【数据结构】B-Tree, B+Tree, B*树介绍 转

    [数据结构]B-Tree, B+Tree, B*树介绍 [摘要] 最近在看Mysql的存储引擎中索引的优化,神马是索引,支持啥索引.全是浮云,目前Mysql的MyISAM和InnoDB都支持B-Tre ...

随机推荐

  1. mysql分割逗号办法

    https://blog.csdn.net/xcymorningsun/article/details/73436568

  2. TestNG安装及使用

    安装:https://www.cnblogs.com/xusweeter/p/6559196.html使用:https://www.cnblogs.com/liwu/p/5113936.html 作用 ...

  3. Scrapy安装报错

    python3 pip 安装Scrapy在win10 安装报错error: Microsoft Visual C++ 14.0 is required. Get it with "Micro ...

  4. axios拦截器

    import axios from "axios"; axios.interceptors.response.use(response => { //=>设置响应拦截器 ...

  5. vue脚手架搭建项目引用百度地图--出坑

    这是官网地址 https://dafrok.github.io/vue-baidu-map/#/zh/start/installation 需要声明注意的是 BaiduMap 组件容器本身是一个空的块 ...

  6. 7 Servlet 会话技术

    1 什么是会话 用户开一个浏览器访问某个网站,点击多个链接,访问服务器多个web资源,然后关闭浏览器,整个过程称之为会话,与打电话类似.会话过程要解决一些问题, 每个用户在使用浏览器与服务器进行会话时 ...

  7. Linux(Ubuntu 16) 下Java开发环境的配置(二)------Tomcat的配置及常见问题

    前言 相比于java JDK的配置,Tomcat的配置简单的多,简直就相当于直接运行了,本文以Tomcat8.0为例进行配置   1.Tomcat的下载 地址:https://tomcat.apach ...

  8. 企业nginx应用实例(功能拆分记录)

    一.默认访问协议强制跳转(http--->https) server { listen ; server_name dannylinux.top www.dannylinux.top; # re ...

  9. Python抓取天气信息并存储原来这么简单

    我们计划抓取的数据:杭州的天气信息 实现数据抓取的逻辑:使用python 请求 URL,会返回对应的 HTML 信息,我们解析 html,获得自己需要的数据.(很简单的逻辑) 第一步:创建 Pytho ...

  10. Kubernetes 中的渐进式交付:蓝绿部署和金丝雀部署

    渐进式交付是持续交付的下一步, 它将新版本部署到用户的一个子集,并在将其滚动到全部用户之前对其正确性和性能进行评估, 如果不匹配某些关键指标,则进行回滚. 这里有一些有趣的项目,使得渐进式交付在 Ku ...